PDA

Ver la Versión Completa : Otro fallo con fragment


Merche300
15/11/15, 16:37:33
Esta linea es la que me da el error el logcat, ¿porque?

listView.setAdapter(adapter);

y aqui el codigo, a ver que he hecho ahora que no sale. gracias.

import android.app.ProgressDialog;
import android.net.ParseException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;

public class J_Actual extends ListFragment {

ArrayList<Actors> actorsList;

ActorAdapter adapter;

override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {



setRetainInstance(true);

View view = inflater.inflate(R.layout.j_actual, null);



actorsList = new ArrayList<Actors>();
new JSONAsyncTask().execute("http://cadetes.esy.es/conexion/jornadas/aa.php");

ListView listView = (ListView) view.findViewById(android.R.id.list);


adapter = new ActorAdapter(getActivity(), R.layout.j_actual_row, actorsList);

listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {


override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long id) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(), actorsList.get(position).getName(), Toast.LENGTH_LONG).show();
}
});
return view;
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {

ProgressDialog dialog;

override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(J_Actual.this.getActivity());
dialog.setMessage("Cargando, por favor espere");
dialog.setTitle("Conectando con el servidor");
dialog.show();
dialog.setCancelable(false);
}

override
protected Boolean doInBackground(String... urls) {
try {

//------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);

// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();

if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);


JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("actors");

for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);

Actors actor = new Actors();

actor.setName(object.getString("nomLocal"));
actor.setDescription(object.getString("resulLocal"));
actor.setDob(object.getString("nomVisitante"));
actor.setCountry(object.getString("fecha"));
actor.setHeight(object.getString("hora"));
actor.setSpouse(object.getString("estadoPartido"));
actor.setChildren(object.getString("resulVisitante"));

actor.setesc_local("http://ffcv.es/ncompeticiones/" + (object.getString("escudoLocal")));
actor.setImage2("http://ffcv.es/ncompeticiones/" + (object.getString("escudoVisitante")));

actorsList.add(actor);
}
return true;
}

//------------------>>

} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}

protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if(result == false)
Toast.makeText(getActivity(), "No se ha podido obtener los datos desde el servidor", Toast.LENGTH_LONG).show();

}
}
}


Logcat:

11-15 16:39:32.538 19160-19160/? E/AndroidRuntime: at com.My_Aplicacion.J_Actual.onCreateView(J_Actual.j ava:55)

kriogeN
15/11/15, 19:52:27
El error no sale entero, te has comido justo la parte donde lo indica. Pero me juego lo que sea a que es un NullPointerException y listView es NULL.

¿Seguro que tu ListView se llama android.R.id.list?

ListView listView = (ListView) view.findViewById(android.R.id.list);

Dexafree
15/11/15, 22:03:35
El error no sale entero, te has comido justo la parte donde lo indica. Pero me juego lo que sea a que es un NullPointerException y listView es NULL.

¿Seguro que tu ListView se llama android.R.id.list?

ListView listView = (ListView) view.findViewById(android.R.id.list);

Mi voto va por eso mismo

Merche300
16/11/15, 00:46:43
Si seguro que se el listview se llama list, y aqui todo el logcat:

el j_actual.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/label_jornadas"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:background="#F1F1F1"
tools:context=".MainActivity" >

<TextView

android:id="@+id/textView2" style="@style/label_jornadas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="JORNADA SEMANAL"
android:layout_gravity="center_horizontal"
android:textColor="@color/naranja" />

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/row" >

</ListView>

</LinearLayout>

Y el Logcat entero:

11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: FATAL EXCEPTION: main
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: Process: com.rafelcf, PID: 27558
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget. ListAdapter)' on a null object reference
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at com.herprogramacion.restaurantericoparico.J_Actual .onCreateView(J_Actual.java:55)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView( Fragment.java:1962)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToS tate(FragmentManager.java:1026)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToS tate(FragmentManager.java:1207)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.app.BackStackRecord.run(BackSta ckRecord.java:738)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPen dingActions(FragmentManager.java:1572)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execute PendingTransactions(FragmentManager.java:545)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.app.FragmentStatePagerAdapter.f inishUpdate(FragmentStatePagerAdapter.java:163)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.view.ViewPager.populate(ViewPag er.java:1106)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.view.ViewPager.populate(ViewPag er.java:952)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.view.ViewPager.onMeasure(ViewPa ger.java:1474)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.RelativeLayout.measureChildHorizont al(RelativeLayout.java:715)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.RelativeLayout.onMeasure(RelativeLa yout.java:461)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(Vie wGroup.java:5951)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayo ut(LinearLayout.java:1465)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(Linear Layout.java:748)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout .java:630)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v4.widget.DrawerLayout.onMeasure(D rawerLayout.java:940)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(Vie wGroup.java:5951)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.j ava:194)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.support.v7.internal.widget.ContentFrameLay out.onMeasure(ContentFrameLayout.java:124)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(Vie wGroup.java:5951)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayo ut(LinearLayout.java:1465)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(Linear Layout.java:748)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout .java:630)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(Vie wGroup.java:5951)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.j ava:194)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(Vie wGroup.java:5951)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayo ut(LinearLayout.java:1465)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(Linear Layout.java:748)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout .java:630)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(Vie wGroup.java:5951)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.j ava:194)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at com.android.internal.policy.PhoneWindow$DecorView. onMeasure(PhoneWindow.java:2643)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.View.measure(View.java:18788)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewRootImpl.performMeasure(ViewRootI mpl.java:2100)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewRootImpl.measureHierarchy(ViewRoo tImpl.java:1216)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRo otImpl.java:1452)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl .java:1107)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(Vi ewRootImpl.java:6013)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Chor eographer.java:858)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreograph er.java:670)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.j ava:606)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiv er.run(Choreographer.java:844)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739 )
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95 )
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
11-16 00:41:24.135 27558-27558/com.rafelcf E/AndroidRuntime: at android.app.ActivityThread.ma

Merche300
16/11/15, 08:15:33
Por si sirve de algo. creo que si, aqui dejo lo mismo como activity y funcionando correctamente.

import android.app.Activity;
import android.app.ProgressDialog;
import android.net.ParseException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;

public class JJ_Actual extends Activity {

ArrayList<Actors> actorsList;

ActorAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.j_actual);
actorsList = new ArrayList<Actors>();
new JSONAsyncTask().execute("http://cadetes.esy.es/conexion/jornadas/aa.php");

ListView listview = (ListView)findViewById(R.id.list);
adapter = new ActorAdapter(getApplicationContext(), R.layout.j_actual_row, actorsList);

listview.setAdapter(adapter);

listview.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), actorsList.get(position).getName(), Toast.LENGTH_LONG).show();
}
});
}


class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {

ProgressDialog dialog;

@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(JJ_Actual.this);
dialog.setMessage("Cargando, por favor espere");
dialog.setTitle("Conectando con el servidor");
dialog.show();
dialog.setCancelable(false);
}

@Override
protected Boolean doInBackground(String... urls) {
try {

//------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);

// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();

if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);


JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("actors");

for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);

Actors actor = new Actors();

actor.setName(object.getString("nomLocal"));
actor.setDescription(object.getString("resulLocal"));
actor.setDob(object.getString("nomVisitante"));
actor.setCountry(object.getString("fecha"));
actor.setHeight(object.getString("hora"));
actor.setSpouse(object.getString("estadoPartido"));
actor.setChildren(object.getString("resulVisitante"));

actor.setesc_local("http://ffcv.es/ncompeticiones/" + (object.getString("escudoLocal")));
actor.setImage2("http://ffcv.es/ncompeticiones/" + (object.getString("escudoVisitante")));

actorsList.add(actor);
}
return true;
}

//------------------>>

} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}

protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if(result == false)
Toast.makeText(getApplicationContext(), "No se ha podido obtener los datos desde el servidor", Toast.LENGTH_LONG).show();

}
}






}

kriogeN
16/11/15, 08:46:12
No, el ListView no se llama así, el ListView se llama R.id.list, no android.R.id.list. Son cosas distintas.

Merche300
16/11/15, 09:52:38
No, el ListView no se llama así, el ListView se llama R.id.list, no android.R.id.list. Son cosas distintas.
Pues, vaya fallo, muchas gracias, en cuanto llegue a casa lo hago

Merche300
16/11/15, 12:25:57
Pues nada, asi se queda igual:

ListView listView = (ListView) view.findViewById(R.id.list);

11-16 12:25:02.317 8083-8083/com.rafelcf E/AndroidRuntime: FATAL EXCEPTION: main
11-16 12:25:02.317 8083-8083/com.rafelcf E/AndroidRuntime: Process: com.rafelcf, PID: 8083
11-16 12:25:02.317 8083-8083/com.rafelcf E/AndroidRuntime: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

ARREGLADO
Pues resulta que así funciona, por si surge alguien con mi problema.

ListView listView = (ListView) view.findViewById(android.R.id.list);

<ListView
android:id="@+id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/row" >

Muchas gracias a kriogeN y a Dexafree por vuestro tiempo.

mocelet
16/11/15, 14:37:46
Eso es por extender de ListFragment en vez de Fragment a secas, que Android obliga a que se llame así si quieres poner tu propio layout.

Te hubiera pasado lo mismo al extender de ListActivity en vez de Activity a secas (que es el ejemplo que te funcionaba)

Tampoco tiene mucho sentido usar ListFragment si ya en el código haces todo para inflar la lista y poblarla con el adaptador.

kriogeN
16/11/15, 16:47:30
Eso es por extender de ListFragment en vez de Fragment a secas, que Android obliga a que se llame así si quieres poner tu propio layout.

Te hubiera pasado lo mismo al extender de ListActivity en vez de Activity a secas (que es el ejemplo que te funcionaba)

Tampoco tiene mucho sentido usar ListFragment si ya en el código haces todo para inflar la lista y poblarla con el adaptador.

Estoy deseando que Google haga deprecated ya los ListView y todo lo que ello conlleva. Con lo bien que funcionan los RecyclerView. Además de la posibilidad de con el mismo adaptador tener listados en vertical, horizontal y grids, sólo cambiando al LayoutManager del RecyclerView.

Desde que los descubrí no uso ListView para nada.

Dexafree
17/11/15, 11:20:22
Estoy deseando que Google haga deprecated ya los ListView y todo lo que ello conlleva. Con lo bien que funcionan los RecyclerView. Además de la posibilidad de con el mismo adaptador tener listados en vertical, horizontal y grids, sólo cambiando al LayoutManager del RecyclerView.

Desde que los descubrí no uso ListView para nada.


Amen.

Por poner una pega, solo les falta un onItemClickListener que no incluya hacer el copiar-pegar de la clase de StackOverflow cada vez que inicias un proyecto xD

Merche300
17/11/15, 21:50:43
Estoy deseando que Google haga deprecated ya los ListView y todo lo que ello conlleva. Con lo bien que funcionan los RecyclerView. Además de la posibilidad de con el mismo adaptador tener listados en vertical, horizontal y grids, sólo cambiando al LayoutManager del RecyclerView.

Desde que los descubrí no uso ListView para nada.
Mañana buscare algún tuto o ejemplos, ando escaso de tiempo, y no se ni como empezar así. gracias

Merche300
07/12/15, 01:39:29
Estoy deseando que Google haga deprecated ya los ListView y todo lo que ello conlleva. Con lo bien que funcionan los RecyclerView. Además de la posibilidad de con el mismo adaptador tener listados en vertical, horizontal y grids, sólo cambiando al LayoutManager del RecyclerView.

Desde que los descubrí no uso ListView para nada.

Bueno te he hecho caso, y me parece que hago bien, es muchisimo mas rapido que lo que usaba, pero tengo otro fallo para pasar a fragment.

El ActionBarActivity:


import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class J_Actual extends ActionBarActivity {

// Atributos
ListView listView;
ArrayAdapter adapter;

override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_volley);

// Obtener instancia de la lista
listView= (ListView) findViewById(R.id.listView);

// Crear adaptador y setear
adapter = new J_Actual_Adapter(this);
listView.setAdapter(adapter);

}


override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}


y el Fragment para podre meterlo en un tab:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class J_Actual extends Fragment {

// Atributos
ListView listView;
ArrayAdapter adapter;

override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

//setRetainInstance(true);

return inflater.inflate(R.layout.activity_volley, container, false);


// Obtener instancia de la lista
listView = (ListView) getView().findViewById(R.id.listView);

// Crear adaptador y setear
adapter = new J_Actual_Adapter(this, R.layout.post, R.id.labeld, listView);

listView.setAdapter(adapter);


}


override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}



Pues bien en esta linea:

adapter = new J_Actual_Adapter(this, R.layout.post, R.id.labeld, listView);

¿Que es el R.id.labeld?

Es lo unico que tengo en rojo y lo que me dice el logcat.

kriogeN
07/12/15, 09:53:03
Bueno te he hecho caso, y me parece que hago bien, es muchisimo mas rapido que lo que usaba, pero tengo otro fallo para pasar a fragment.

El ActionBarActivity:


import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class J_Actual extends ActionBarActivity {

// Atributos
ListView listView;
ArrayAdapter adapter;

override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_volley);

// Obtener instancia de la lista
listView= (ListView) findViewById(R.id.listView);

// Crear adaptador y setear
adapter = new J_Actual_Adapter(this);
listView.setAdapter(adapter);

}


override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}


y el Fragment para podre meterlo en un tab:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class J_Actual extends Fragment {

// Atributos
ListView listView;
ArrayAdapter adapter;

override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

//setRetainInstance(true);

return inflater.inflate(R.layout.activity_volley, container, false);


// Obtener instancia de la lista
listView = (ListView) getView().findViewById(R.id.listView);

// Crear adaptador y setear
adapter = new J_Actual_Adapter(this, R.layout.post, R.id.labeld, listView);

listView.setAdapter(adapter);


}


override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}



Pues bien en esta linea:

adapter = new J_Actual_Adapter(this, R.layout.post, R.id.labeld, listView);

¿Que es el R.id.labeld?

Es lo unico que tengo en rojo y lo que me dice el logcat.

Esa clase es propia tuya, no es de Android, así que si no lo sabes tú...

De todas formas tiene pinta de ser como un ArrayAdapter, y en ese caso sería el campo de texto asociado al elemento en cada uno de los elementos del Adapter.

En otras palabras, tiene pinta de ser un TextView dentro de R.layout.post

Merche300
08/12/15, 12:03:37
pues no hay manera:

jornadas_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">



<TextView

android:id="@+id/tv_fecha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:gravity="center"
android:textSize="18dp"
android:background="#cfcfcf" />

<ImageView

android:id="@+id/tv_escudo_local"
android:layout_width="50dp"
android:layout_height="85dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp" />

<TextView

android:id="@+id/tv_equipo_local"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#000000"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal" />

<TextView

android:id="@+id/tv_resultado_local"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:textStyle="bold"
android:textSize="28dp"
android:textColor="#0265d0"
android:layout_centerHorizontal="true"
android:layout_below="@+id/tv_equipo_local"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal" />

<TextView

android:id="@+id/tv_equipo_visitante"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#000000"
android:layout_centerHorizontal="true"
android:layout_below="@+id/tv_resultado_local"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal" />

<ImageView

android:id="@+id/tv_escudo_visitante"
android:layout_width="50dp"
android:layout_height="85dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="25dp" />

</RelativeLayout>

Dexafree
08/12/15, 12:12:01
1. Tienes una Activity y un Fragment que se llaman igual? (J_Actual)
2. Tu clase J_Actual_Adapter, segun lo que se puede deducir de tu codigo, tiene 2 constructores, uno que recibe un context y otro que recibe 2 enteros y una referencia al listview (dios sabe para que).
3. Si dices que R.id.labelid te sale en rojo es porque no tienes ningun elemento en tus xml con id labelid, asi que lo primero que deberias hacer es intentar averiguar que hace tu clase J_Actual_Adapter con esos ids... pero vamos, no me parece muy normal esa reutilizacion de adapters :pensando: