2
배열에서 listview를 표시 할 수 있습니다. 그러나 행 응용 프로그램에서 임의의 행을 클릭하면 오류가 발생합니다. ClassCaste Exception android.widget.linearlayout. 내 XML은 :linearviewout에서 textView에 액세스 할 수 없습니다 onItemClick의 listview에서 findViewById를 사용합니다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@+id/icon" android:layout_height="wrap_content"
android:src="@drawable/icon" android:layout_width="22px"
android:layout_marginTop="4px" android:layout_marginRight="4px"
android:layout_marginLeft="4px">
</ImageView>
<TextView android:text="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/label"
android:textSize="30px"></TextView>
는 특정 코드 오류가있을 수있는 곳 :
ArrayAdapter<String> countryAdapter=new ArrayAdapter<String>(this,R.layout.rowlayout,R.id.label,countries);
setListAdapter(countryAdapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(this);
과의 onclick 방법, 나는 목록보기에서 clickd 항목에 토스트를 보여주기 위해 노력하고 여기서
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), ((TextView)linearlayout.findViewById(R.id.label)).getText(), Toast.LENGTH_SHORT).show();
}
목록 항목 중 하나를 클릭 할 때 응용 프로그램이 충돌합니다.
제안 사항? 감사
무슨 짓을 교체? Toast.makeText (getApplicationContext(), (TextView) linearlayout.findViewById (R.id.label)). getText(), Toast.LENGTH_SHORT) .show(); – Venky
'onItemClick' 메쏘드에서, 어디에서'linearLayout' 레퍼런스를 얻고 있습니까? – anirvan
(이미 선언 된) 선형 레이아웃의 자식 노드에 액세스하려고 시도하고 textview.my 바보 같은 마음에 typecasting :( – Alok