I am not able to get the hidden field value of the clicked item.
I followed SO Post to get the hidden value of the clicked listview item but
unable to get the value. I am getting ClassCastException
.
The code -
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
}
My error log -
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)
UPDATE:
I have defined the above textview in hidden field in xml-
<TextView
android:id="@+id/vehicle_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:visibility="gone"/>
Now I am trying to set its value for each listview item as -
TextView vehicleSrc = (TextView) vi.findViewById(R.id.vehicle_source);
if(isCondition1)
vehicleSrc.setText("Normal");
else
vehicleSrc.setText("Other");
end