How to Get the Value of a Listview Item Which Is Clicked in Android

How to get the value of a Listview item which is clicked in android?

maybe this example will help you

  lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});

https://developer.android.com/reference/android/widget/ListView.html

get string value from item clicked in a listView

I would try something like this, which has worked for me in the past:

String  itemValue    = (String) listView.getItemAtPosition(position);

This is from within the listView.setOnItemClickListener(new OnItemClickListener() portion of your code.

If your strings are aggregated into one string, then try this:

//Let itemValue = "item1 item2 item3" for example:
String[] parts = itemValue.split(" ");
String part1 = parts[0]; // item1
String part2 = parts[1]; // item2

How to Get Value from item listview when clicked Android Studio?

Instead of String nama = modelListViewArrayList.get(i).getNama();

Try this String nama = ((ModelListView) lv.getAdapter().getItem(i)).getNama();

OnItemClick how to get text value of clicked item from list view

I am able to receive the data but not as is displayed eg. Instead of receiving the list item "Christmas", I am getting something like "com.example.johndoe.project.Category@fa9dc73"

Because adapterView.getItemAtPosition(i) Might Returning you custom Model class not String value

Try this

lv_categories.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
YourModelClass data = adapterView.getItemAtPosition(i);

SM.sendData(data.getMessage);
}
});

Get value of list view edittext in button click android

Create a method in adapter which returns the list which it is using.
Like :

public ArrayList<AtomPayment> getList() {
return items;
}

Then in onClick of save button call this method.
Like :

List<AtomPayment> paymentList = adapter.getList();

And use this list for further operations.

mButtonSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
List<AtomPayment> paymentList = adapter.getList();
Log.d("Finalitems",String.valueOf(paymentList.size()));
for (int i=0;i<items.size();i++)
{
Log.d("Name",paymentList.get(i).getName());
Log.d("Value",String.valueOf(paymentList.get(i).getValue()));
}
}
});

How to get value of Selected Listview item to String?

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)

{
String Name =((TextView)view.findViewById(R.id.price_name)).getText().toString();

Log.d("string",Name);

        }
});

How to get the value of clicked item of a custom listview inside the AlertDialog?

Actually, this is an answer for this question. I have added android: inputType="text" to the code. It was the problem. I removed it and then it works perfectly.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/match_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin_10dp"
android:weightSum="3">

<TextView
android:id="@+id/customer_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Username"
android:layout_weight="1"
android:textColor="@color/colorBlack"
android:textSize="@dimen/text_size_18sp" />


<TextView
android:id="@+id/customer_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="id"
android:layout_weight="2"
android:textColor="@color/colorBlack"
android:textSize="@dimen/text_size_18sp" />
</LinearLayout>

<View
android:id="@+id/bottom_border"
android:layout_width="match_parent"
android:layout_height="0.8dp"
android:layout_marginTop="@dimen/activity_margin_5dp"
android:background="@color/colorGrey" />

</LinearLayout>

The answer was given by the "I_A_Mok", All the credits should goes to him.



Related Topics



Leave a reply



Submit