これは私が非常に興味があるという奇妙な質問です。私はプロファイルのリストビューを持っています。特定のプロファイルをクリックすると、そのプロファイルを単独で表示したいのです。私がリストビューで項目を選択しようとすると、一般的には機能しませんが、何らかの奇妙な理由で時には(約10分の1)機能します。それはよりイライラする。誰もこの問題を抱えていましたか?ありがとうございました。 (私はこれに似た質問を投稿しました。それはまったく動かなかったので、重複しないでください、ありがとう)。リストビューonItemClickが期待どおりに機能しない
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>
は、あなたがそれをデバッグしたのですか? –
あなたのアイテムアダプタのレイアウトを投稿してください。私はあなたのレイアウトで動作する例を作ったが、あなたが持っているものを確認するためにあなたのアダプタレイアウトが必要です。 –
こんにちは、返信ありがとう、しかし私は上に投稿したXMLにある単純なリストのアダプタを使用していますか?それとも、それが正しいのではない方法ですか?再度、感謝します。 – user3597639