0
我想獲取listview的子項並將其兩個隱藏元素的可見性設置爲true。 我的代碼是無法對listView的子進行操作
canvasListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/*
joinCanvasBtn.setEnabled(true);
joinCanvasPasswordTxt.setEnabled(true);*/
Log.d(TAG,"Selected positon : "+position);
int index = canvasListView.getFirstVisiblePosition() + position;
View v = canvasListView.getChildAt(index);
if(v!=null) {
joinCanvasBtn = (Button) v.findViewById(R.id.joinCanvasBtn);
canvasPassword = (EditText) v.findViewById(R.id.joinCanvasPasswordTxt);
joinCanvasBtn.setVisibility(View.VISIBLE);
joinCanvasPasswordTxt.setVisibility(View.VISIBLE);
}
else {
Log.d(TAG,"Unable to find the selected child of listView");
}
}
});
但這不是它的工作給我空指針異常。我的佈局文件如下。基本上我想顯示密碼和加入按鈕,每當用戶點擊該行。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<!-- Item Name -->
<TextView
android:id="@+id/canvasName"
android:height="100dp"
/>
<TextView
android:id="@+id/canvasCreator"
android:text="TextView" />
<EditText
android:id="@+id/joinCanvasPasswordTxt"
android:visibility="invisible"
/>
<Button
android:id="@+id/joinCanvasBtn"
android:text="Join"
android:visibility="invisible"
/>
</LinearLayout>
請幫我找到解決辦法
如果(指數> = 0){.. setVisibility真正的代碼。 ..)}其他{Log.d(TAG,「請選擇」);}可以幫助 –
,不會幫助我試過 – nikhilbhr