das ist eine komische Frage, die mich sehr interessiert. Ich habe eine Liste von Profilen und wenn ich auf ein bestimmtes Profil klicke, möchte ich dieses Profil selbst anzeigen. Wenn ich versuche, ein Element in der Listenansicht auszuwählen, funktioniert es im Allgemeinen nicht, aber es funktioniert manchmal (etwa 1 zu 10) aus irgendeinem seltsamen Grund. Was es frustrierender macht. Hat jemand jemals dieses Problem gehabt? Vielen Dank. (Ich habe eine ähnliche Frage gestellt, in der ich dachte, dass es gar nicht funktioniert, also bitte nicht duplizieren, danke).Listview onItemClick funktioniert nicht wie erwartet
public class CowListView extends ListActivity {
RegisterCowAdapter cowAdapter;
private DataBaseHelper databaseHelper;
public ListView listView;
TextView student_Id;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cow_list_item);
cowAdapter = new RegisterCowAdapter(this);
cowAdapter.open();
updateCowUI();
listView = (ListView) findViewById(android.R.id.list);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
student_Id = (TextView) view.findViewById(R.id.cowtagnolist);
String studentId = student_Id.getText().toString();
Intent i = new Intent(view.getContext(), CowProfile.class);
Toast.makeText(CowListView.this, "Clicked", Toast.LENGTH_SHORT).show();
i.putExtra("student_Id", Integer.parseInt(studentId));
Log.d("StartingCow", studentId);
startActivityForResult(i, 0);
}
});
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:longClickable="true"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false">
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
<TextView
android:id="@+id/cowtagnolist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/black"
android:clickable="true">
</TextView>
<TextView
android:id="@+id/cowdoblist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="17dp"
android:clickable="true"
android:textColor="@color/black">
</TextView>
</LinearLayout>
hast du es debuggt? –
posten Sie bitte das Layout Ihrer Artikel Adapter, ich habe ein Beispiel, das mit Ihrem Layout arbeiten, aber ich brauche Ihr Adapter-Layout, um zu überprüfen, was Sie dort haben. –
Hallo, danke für die Antwort, aber ich benutze einen einfachen Listenadapter, der in der XML, die ich oben gepostet habe, ist? Oder ist diese Methode nicht korrekt? Danke noch einmal. – user3597639