android:how to reload the listview in multiple selection time - android

Hi Friends I when i click the checkbox..i want to refresh the listview because when i check there are no effect in current view but when i scroll down that is perform so i want to reload the view so how can i reload the view in listview chckbox click event??

u can use listmethod ie notifyDataSetChanged()

You can use
cb.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
....
Where cb is a checkbox.
Within this listener you can refresh your list adapter, use lv.setAdapter, where lv is setAdapter.
You can also search refreshing a list adapter view you can search setadapter method. I hope that is what you want.

Related

Change Parent layout from setOnItemClickListener()

I have an Activity a with a ListView lv inside.
I have set the lv.setOnItemClickListener().
When the user clicks on a list item i want another list view (ListView lv_2) in the Activity a to be refreshed.
Problem is that i cannot access the Parent Activity a inside lv.setOnItemClickListener() am i right?
I studied some of custom event listeners but i don't understand how to use them in this particular case.
So how can i do this?
lv1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
lv2Adapter.notifyDataSetChanged();
lv2.setAdapter(lv2Adapter);
lv2.notify();
}
});

Update ListView in ArrayAdapter when a row button clicked

I have a class OwnAdapter which extends the ArrayAdapter.
Data to it is passed in a arrayList.
There is a custom layout contaning 2 TextViews and 2 Buttons.
I have defined the onClick actions on the buttons in the getView method of the adapter itself.
When the button of the rows are clicked there are some changes made to the database.Now I am not getting how to update the listview when either of the 2 buttons are clicked and show the new data.
bAttend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//works fine
upDateAttend(position);
//code for updating view-What to add here?
notifyDataSetChanged();
}
});
after updating your arraylist make this line
youradapter.notifyDataSetChanged();
if you updating the arraylist in the adpater just add notifyDataSetChanged();
see this link ,talk about recyclerview but will help you
https://guides.codepath.com/android/using-the-recyclerview#notifying-the-adapter

setText method not working for editText in listview after calling 'notifyDataSetChanged'

I'm developing an android application using eclipse. I have a listview and each row of this contains an EditText. When I click on an EditText I want two things to do.
1: Reload all the EditText with texts from my data array.
2: Set the text of the clicked EditText to a constant string(say "0").
For this I used the below onclicklisetner for EditText.
myEdittext.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
adapter.notifyDataSetChanged();//adapter is my arrayadapter of the listview
EditText clickedText = (EditText)v;
clickedText.setText("0");
}
});
As you can see I'm using 'notifyDataSetChanged' method to reload the EditTexts in the listview and 'setText' method to set the clicked EditText's text to "0".
But the 'setText' method is not working. If I comment the line 'adapter.notifyDataSetChanged()' the 'setText' method is working.
I also tried to do this by calling the setText method after a delay(to check if the notifyDataSetChanged is starting a new thread) but failed.
How can I make both the methods to work in my onClick method.
Thanks in Advance.
You can do it using another approach.
You might be setting the ListView adapter using an ArrayList say mList.
Now in the onItemClick listener of the list view you get the position of the item clicked in the ListView. In the onClick() set the value 0 at that position of the arrayList eg mList.set(position, 0). and then call notifyDataChanged()
try :
So the reason for such behavior is that when you call adapter.notifyDataSetChanged(), there is a good chance that your View V is recycled hence it no longer refers to the one that is clicked. What you really want to do is to change the list so that when notifyDataSetChanged is called then all the values will be loaded accordingly.
Please share your adapter code.
myEdittext.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
//adapter is my arrayadapter of the listview
//EditText clickedText = (EditText)v;
//clickedText.setText("0");
//Do some thing to change the adapter data list.
adapter.notifyDataSetChanged();
}
});

Activity refresh command from custom listview

Environment: Android 2.2+
I have an Activity. The Activity creates a custom listview with its adapter and populates it. When the user clicks on an item (an ImageView thumbnail) in the list, a context menu is shown. The repercussion of selection is that the view of Activity needs to be refreshed.
My question is: How can I send a command from the onClick of the custom adapter to the Activity asking to refresh itself?
Activity
...
ListView lv;
lv = (ListView) findViewById(R.id.lvlist);
lv.setAdapter(null);
MyCustomAdapter lvAdapter = new MyCustomAdapter(...);
lv.setAdapter(lvAdapter);
lv.setOnItemClickListener(myClickListener);
...
MyCustomAdapter (There is a thumbnail ImageView inside each list item called ivLogo)
...
ivLogo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Carry out some tasks
// At this point inform Activity that it needs to refresh
}
});
It must be noted that I'm not looking for anything in myClickListener. I want a signal from the thumbnail's onClickListener.
I scoured the internet, but could not find anything helpful for this specific case.
Any help/pointers will be much appreciated.
TIA
-sph
add this line to your onClick()
lvAdapter.notifyDataSetChanged();
you write his code whenever you need adpater refreshed...its worked
lvAdapter .notifyDataSetChanged();

Selected Item of row in ListView

Hi I am using a Listview in my application and I created separate xml for the layout of each row of that ListView. Each row contains two ImageView and one One TextView. I want to get which ImageView is clicked on that row.
You can set OnClickListener in Adapter class itself inside getView() and get the Click Listener working for both the images. As, you haven't posted any code it not feasible to guess.
put the tag with each imageView in getView function of the adapter....
imageView.setTag(Postion);
and get in onclick with view that you received......
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
system.out.println("position"+position)
}});

Categories

Resources