我无法获取单击项目的隐藏字段值。
我按照SO Post获取单击的列表视图项的隐藏值,但无法获取该值。我越来越ClassCastException
。
编码 -
listView.setOnItemClickListener(new OnItemClickListener()
{
//////////list view on click
public void onItemClick(AdapterView<?> view, View arg1,
int position, long arg3) {
String S = (String)view.getItemAtPosition(position); //This line gives exception
System.out.println("TextView vehicleSrc>>"+S);
//OR
String itemSelected = ((TextView)view.findViewById(R.id.vehicle_source)).getText().toString();
System.out.println("TextView vehicleSrc"+itemSelected); // this is giving blank
}
我的错误日志 -
03-20 12:47:08.742: E/AndroidRuntime(26965): FATAL EXCEPTION: main
03-20 12:47:08.742: E/AndroidRuntime(26965): java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
03-20 12:47:08.742: E/AndroidRuntime(26965): at com.iddl.main.EntryFragment$13$2.onItemClick(UserFragment.java:907)
更新:
我在xml的隐藏字段中定义了上面的textview-
<TextView
android:id="@+id/vehicle_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:visibility="gone"/>
现在我正在尝试将每个列表视图项的值设置为 -
TextView vehicleSrc = (TextView) vi.findViewById(R.id.vehicle_source);
if(isCondition1)
vehicleSrc.setText("Normal");
else
vehicleSrc.setText("Other");
end