I'm trying to create a gridview that gives the possibility to the user to create a new child clicking on the last item on the gridview. I have a problem redrawing the view. In fact after the user creates a new child through an alertdialog I need to refresh the gridview to make this child visible. I've been looking for a solution for a while and everything I found is:
adapter.notifyDataSetChanged();
gridView.invalidateViews();
gridView.setAdapter(adapter);
Which is part of my code but doesn't,at least apparently, do anything. The code below is just the onCreateView() from the PlaceholderFragment class in the android template for an activty with swiping tabs. The app development here is still at the beginning but I'm already stuck with this issue..
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_one, container, false);
final GridView gridView = (GridView) rootView.findViewById(R.id.gridview);
final GridAdapter adapter =new GridAdapter(getActivity());
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
if(position==0){
LayoutInflater inflater = getActivity().getLayoutInflater();
View newidea= inflater.inflate(R.layout.newidea, null);
final TextView txtname = ((TextView) newidea.findViewById(R.id.name));
final TextView txtdesc = ((TextView) newidea.findViewById(R.id.desc));
final Spinner spinner=((Spinner)newidea.findViewById(R.id.spinner));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setIcon(R.drawable.type_add)
.setPositiveButton("Create", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String name = txtname.getText().toString();
String desc = txtdesc.getText().toString();
DataReceiver dr = new DataReceiver(getActivity().getBaseContext(), name, desc,Integer.toString(spinner.getSelectedItemPosition()));
dr.writeFile();
dialog.dismiss();
adapter.notifyDataSetChanged();
gridView.invalidateViews();
gridView.setAdapter(adapter);
}
}).setNegativeButton("Forgot the idea?", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
}).setView(newidea)
.setTitle("New Idea");
AlertDialog dialog = builder.create();
dialog.show();
} else {
Toast.makeText(
getActivity(),
((TextView) v.findViewById(R.id.grid_item_label))
.getText(), Toast.LENGTH_SHORT).show();
}
}
});
return rootView;
}
}
UPDATE after code posting requests.
Here is the GridAdapter. Everything works fine, the only thing is that I still have to close and reopen the app to see the gridview redrawn and updated.
public class GridAdapter extends BaseAdapter {
private Context context;
boolean filesyet;
File f[];
public GridAdapter(Context context) {
this.context = context;
filesyet=filesYet();
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = inflater.inflate(R.layout.griditem, null);
TextView title = (TextView) gridView
.findViewById(R.id.grid_item_label);
LinearLayout background = (LinearLayout) gridView
.findViewById(R.id.grid_item);
if(position==0){
title.setText("");
Drawable d= context.getResources().getDrawable(R.drawable.type_add);
background.setBackground(d);
}else {
title.setText(f[position].getName());
Drawable d;
int selected=0;
try {
byte[] buffer = new byte[1];
new FileInputStream(f[position]).read(buffer,0,buffer.length);
selected=Integer.valueOf(new String(buffer));
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
switch(selected){
case 1:
d=context.getResources().getDrawable(R.drawable.type_app);
break;
case 2:
d=context.getResources().getDrawable(R.drawable.type_engi);
break;
case 3:
d=context.getResources().getDrawable(R.drawable.type_event);
break;
default:
d=context.getResources().getDrawable(R.drawable.eureka);
break;
}
background.setBackground(d);
}
} else {
gridView = (View) convertView;
}
return gridView;
}
#Override
public int getCount() {
if (filesyet) {
return f.length;
} else {
return 1;
}
}
Boolean filesYet(){
try {
String path = context.getFilesDir().toString();
this.f = new File(path).listFiles();
System.out.println(f.toString());
return true;
} catch (NullPointerException e){
System.out.println("NULL");
return false;
}
}
Thanks for helping
You only load a list of files when the adapter is created in the constructor. As you are not creating a new constructor the filesYet() method is not called again and the file list is not updated.
To make this update you could override the notifydatasetchanged function in the adapter
#Override
public void notifyDataSetChanged (){
filesyet = filesYet();
super.notifyDataSetChanged();
}
Related
I am creating an android application in which there is a scenario where i have to add new items to the grid i am using an layout inflater to add new items to the grid the items gets added to the database sucessfully but the grid view is not refreshed once the item is added i have used notify dataset changed but it is not working can anyone tell me what i have to change in the existing code
Activity for the gridview:
listet = databaseHandlerOtherchgs.getAllproducttitle();
listet.add(new OtherChargesType("Plucking", bitMapData));
listet.add(new OtherChargesType("Loading", bitMaploading));
listet.add(new OtherChargesType("Add New", bitMapaddnew));
listcharges = new ArrayList<CustomizedCharge>());
adapter = new OtherChargesGridAdpater(SinglePageTransaction.this, listet);
gv.setAdapter(adapter);
gv.setExpanded(true);
GridAdapter:
public class OtherChargesGridAdpater extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<OtherChargesType> otherchargestypes;
DatabaseHandlerOtherChgs databaseHandlerOtherchgs;
public OtherChargesGridAdpater(Activity activity, List<OtherChargesType> otherchargestypes) {
this.activity = activity;
this.otherchargestypes = otherchargestypes;
}
#Override
public int getCount() {
return otherchargestypes.size();
}
#Override
public Object getItem(int i) {
return otherchargestypes.get(i);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertview, ViewGroup parent) {
if (inflater == null) {
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if (convertview == null) {
convertview = inflater.inflate(R.layout.row_othercharges_griditem, null);
}
OtherChargesType m = otherchargestypes.get(position);
byte[] outImage = m.getImage();
ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
final Bitmap theImage = BitmapFactory.decodeStream(imageStream);
ImageView otherimages = (ImageView) convertview.findViewById(R.id.imageView1);
final TextView typename = (TextView) convertview.findViewById(R.id.textView1);
databaseHandlerOtherchgs=new DatabaseHandlerOtherChgs(activity);
// getting movie data for the row
typename.setText(m.getTypename());
otherimages.setImageBitmap(theImage);
notifyDataSetChanged();
return convertview;
}
public void updatedata(){
DatabaseHandlerOtherChgs databaseHandlerOtherChgs =new DatabaseHandlerOtherChgs(activity);
databaseHandlerOtherChgs.getAllproducttitle();
this.notifyDataSetChanged();
}
}
Use This code in Activity.. This code store your data.
#Override
public void onSaveInstanceState(Bundle outState) {
outState.putString("MSG", "This is my message to be reloaded");
super.onSaveInstanceState(outState);
}
In Oncreate Method put this code
if (savedInstanceState != null) {
String str= savedInstanceState.getString("MSG");
Toast.makeText(this, str, Toast.LENGTH_LONG).show();
}
And for refresh your activity use follow code
finish();
startActivity(getIntent());
Make Changes as per your requirement.
I am having a listview and it has one checkbox and two textfields , i would like to change check box visibility properties from listview on click funtion, i am able to change the properties from inside the getView funtion but i want it from listview click. Help me find a solution
public class HelpList extends Fragment {
amfFunctions amf;
MyCustomAdapter dataAdapter = null;
Database_Contact contact = new Database_Contact();
DBHelper mydb = new DBHelper(getActivity());
public static final int PICK_CONTACT = 1;
public String user_phone_number;
public String buddyName;
public String buddyNum;
LayoutInflater vi;
View v ;
Fragment fragment = null;
Button myAddButton,myDelButton;
int selected = 0;
Boolean isInternetPresent = false;
ConnectionDetector cd;
ArrayList<Database_Contact> selectedList = new ArrayList<>();
Database_Contact addcontacts = new Database_Contact();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.activity_helplist, container, false);
// Inflate the layout for this fragment
displayListView();
cd = new ConnectionDetector(getActivity());
myDelButton = (Button)v. findViewById(R.id.deleteContact);
myDelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
isInternetPresent = cd.isConnectingToInternet();
if (isInternetPresent) {
DeleteContact();
}
else{
Toast.makeText(getActivity(),
getString(R.string.nointernet), Toast.LENGTH_SHORT).show();
}
}
});
Constants.i = 0;
myAddButton = (Button)v. findViewById(R.id.Addanother);
myAddButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
isInternetPresent = cd.isConnectingToInternet();
Log.e("Myaddbutton text ", (String) myAddButton.getText());
if (isInternetPresent) {
if (myAddButton.getText().equals("Close")){
Toast.makeText(getActivity(),
getString(R.string.click_to_close), Toast.LENGTH_SHORT).show();
}
else{
AddContact();
}
}
else{
Toast.makeText(getActivity(),
getString(R.string.nointernet), Toast.LENGTH_LONG).show();
}
}
});
return v;
}
private void displayListView() {
mydb = new DBHelper(getActivity());
ArrayList<Database_Contact> contactlist = (ArrayList<Database_Contact>)
mydb.getAllDatabase_Contacts();
Collections.sort(contactlist, new Comparator<Database_Contact>() {
#Override
public int compare(Database_Contact lhs, Database_Contact rhs) {
return lhs.getName().compareTo(rhs.getName());
}
});
//create an ArrayAdaptar from the String Array
dataAdapter = new MyCustomAdapter(getActivity(),
R.layout.activity_allcontactlist, contactlist);
ListView listView = (ListView)v.findViewById(R.id.helplistview);
// Assign adapter to ListView
listView.setTextFilterEnabled(true);
listView.setAdapter(dataAdapter);
dataAdapter.notifyDataSetChanged();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Database_Contact contact = (Database_Contact)
parent.getItemAtPosition(position);
contact.isSelected();
}
});
}
private class MyCustomAdapter extends ArrayAdapter<Database_Contact> {
private ArrayList<Database_Contact> contactlist;
public MyCustomAdapter(Context context, int textViewResourceId,
ArrayList<Database_Contact> contactlist) {
super(context, textViewResourceId, contactlist);
this.contactlist = new ArrayList<Database_Contact>();
this.contactlist.addAll(contactlist);
}
private class ViewHolder {
TextView code;
TextView Number;
CheckBox name;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
vi = (LayoutInflater) getActivity().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.activity_allcontactlist,
null);
holder = new ViewHolder();
holder.code = (TextView)
convertView.findViewById(R.id.helplist_name);
holder.Number = (TextView)
convertView.findViewById(R.id.helplist_num);
holder.name = (CheckBox)
convertView.findViewById(R.id.checkbox_all);
convertView.setTag(holder);
final ViewHolder finalHolder = holder;
final ViewHolder finalHolder1 = holder;
holder.code.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (finalHolder1.name.isShown() == false){
Constants.i = Constants.i+1;
myDelButton.setEnabled(true);
finalHolder.name.setVisibility(View.VISIBLE);
}
else if(finalHolder1.name.isShown() == true) {
finalHolder.name.setVisibility(View.GONE);
Constants.i = Constants.i-1;
if (Constants.i == 0){
myDelButton.setEnabled(false);
}
}
}
});
holder.Number.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (finalHolder1.name.isShown() == false){
Constants.i = Constants.i+1;
myDelButton.setEnabled(true);
finalHolder.name.setVisibility(View.VISIBLE);
}
else if(finalHolder1.name.isShown() == true) {
finalHolder.name.setVisibility(View.GONE);
Constants.i = Constants.i-1;
if (Constants.i == 0){
myDelButton.setEnabled(false);
}
}
}
});
holder.name.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
Database_Contact contact = (Database_Contact)
cb.getTag();
contact.setSelected(cb.isChecked());
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
Database_Contact contact = contactlist.get(position);
holder.code.setText(contact.getName());
holder.Number.setText(contact.getPhoneNumber());
holder.name.setText("");
holder.name.setChecked(contact.isSelected());
holder.name.setTag(contact);
return convertView;
}
}
}
As I could not find any perfect solution i tried it in a different manner alough its a bit diffenrt from what i wanted i.e on click i used my displayListView() funtion and got the work done
ischeckboxVisible = true;
Runnable run = new Runnable() {
#Override
public void run() {
displayListView();
}
};
getActivity().runOnUiThread(run);
and coming to getView i have used:
if (!ischeckboxVisible)
{
holder.name.setVisibility(View.GONE);
}
if (ischeckboxVisible)
{
holder.name.setVisibility(View.VISIBLE);
}
so every time i do the click it changes the ischeckboxVisible to either true or false and initializes the displatListview() and it works.
I have had help from here Android hide and show checkboxes in custome listview on button click
Hope this might come in handy for some one out there.
Please check below code if it helps you,
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Database_Contact contact = (Database_Contact) contactlist.get(position);
contact.setSelected(!contact.isSelected());
if(contact.isSelected())
{
((CheckBox) view.findViewById(R.id.checkbox_all)).setVisibility(View.VISIBLE);
}
else
{
((CheckBox) view.findViewById(R.id.checkbox_all)).setVisibility(View.GONE);
}
}
});
I would like to add a popup window when the user press the category button. The window will show the list of category available. The related code for the popup window is as follows:
onCreate:
//popup choices
localArrayList = new ArrayList<String>();
localArrayList.add("action 1"); //0
localArrayList.add("action 2"); //1
localArrayList.add("action 3"); //2
localArrayList.add("action 4"); //3
localArrayList.add("action 5"); //4
popUpContents = new String[localArrayList.size()];
localArrayList.toArray(popUpContents);
popupWindowDogs = ppopupWindowDogs();
actions for pressing the button
public void onClickBtn_action(View v)
{
switch (v.getId())
{
case R.id.btn_category:
popupWindowDogs.showAsDropDown(v, -5, Constants.SCREEN_H / 15); break;
default:
return;
}
}
The popup window:
public PopupWindow ppopupWindowDogs()
{
final PopupWindow localPopupWindow = new PopupWindow(this);
ListView lv = new ListView(this);
lv.setAdapter(new MyCustomArrayAdapter_POP(DB_Ex_ListActivity.this));
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
if (position == 0)
{
}
localPopupWindow.dismiss();
}
});
localPopupWindow.setFocusable(true);
localPopupWindow.setOutsideTouchable(true);
localPopupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
localPopupWindow.setWidth(Constants.SCREEN_W / 2);
localPopupWindow.setHeight(Constants.SCREEN_H );
localPopupWindow.setContentView(lv);
return localPopupWindow;
}
private class MyCustomArrayAdapter_POP extends BaseAdapter
{
private LayoutInflater mInflater;
private Context mContext = null;
public MyCustomArrayAdapter_POP(Context context)
{
mContext = context;
mInflater = LayoutInflater.from(mContext);
}
public int getCount()
{
return localArrayList.size();
}
public Object getItem(int arg0)
{
return localArrayList.get(arg0);
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.listview_item, null);
}
TextView lv_item_text = (TextView) convertView.findViewById(R.id.lv_item_text);
lv_item_text.setText(category_list.get(position));
}
convertView.setLayoutParams(new ListView.LayoutParams((int)(Constants.SCREEN_W/2), (int)(Constants.SCREEN_W/7)));
return convertView;
}
}
Question:
The popup does not show up when the button is pressed.
The Logcat reports
Attempted to finish an input event but the input event receiver has already been disposed.
Add the following line of code below your call to showAsDropDown
popupWindowDogs.update(v,200,300 );
Adjust the 200 and 300 as per the width and height of the pop up.
That's it!
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0)
{
} else{
localPopupWindow.dismiss();
}
}
});
put your localPopupWindow.dismiss() call in else, as when the if condition is failing , it will execute the next line which is localPopWindow.dimiss()
I read many more realted to this problem but not getting more idea. After this, i am trying to post, here in this picture I have 3 items on list, I have 2 item click. So I want to delete these two checked item. But i am the newbie for android, So could not get more idea behind this.
Code
public class CountryList extends Activity implements OnClickListener,
OnItemClickListener {
private static class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return tempCountry.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.bookmarks_list_item,
null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView
.findViewById(R.id.country);
holder.checkBox = (CheckedTextView) convertView
.findViewById(android.R.id.checkbox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtcnt.setText(country[position]);
return convertView;
}
static class ViewHolder {
TextView txtcnt;
CheckBox checkBox;
}}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bokmarksjoks);
try {
db = (new DatabaseHelper(this)).getWritableDatabase();
} catch (IOException e) {
e.printStackTrace();
}
lv = (ListView) findViewById(R.id.list);
btn_delete = (Button) findViewById(R.id.delete);
btn_delete.setOnClickListener(this);
checkbox = (CheckBox) findViewById(R.id.checkbox);
txtname= (TextView) findViewById(R.id.body);
String name= pref.getString("name", "");
country= name.split(",");
lv.setAdapter(new EfficientAdapter(this));
lv.setItemsCanFocus(false);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setOnItemClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.delete:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder .setMessage("Are you Sure want to delete checked country ?")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// how to remove country
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.setTitle("Delete Country");
alert.show();
case R.id.checkbox:
//What is the procedue in this section
default:
break;
}
}
public void onItemClick(AdapterView<?> pareant, View view, int position,
long id) {
try {
// I have trying this but could not proper output or only errors
SparseBooleanArray sp = lv.getCheckedItemPositions();
/*String str = "";
for (int i = 0; i < sp.size(); i++) {
str += country[sp.keyAt(i)] + ",";
}*/
} catch (Exception e) {
e.printStackTrace();
}}}
This is the only three country, actually, I have more then hundreds countries.
Delete items from tempCountry and then call adapter.notifyDataSetChanged().
Have a button on list and let it onclick feature in xml
like to get postion first
public void OnClickButton(View V){
final int postion = listView.getPositionForView(V);
System.out.println("postion selected is : "+postion);
Delete(postion);
}
public void Delete(int position){
if (adapter.getCount() > 0) {
//Log.d("largest no is",""+largestitemno);
//deleting the latest added by subtracting one 1
comment = (GenrricStoring) adapter.getItem(position);
//Log.d("Deleting item is: ",""+comment);
dbconnection.deleteComment(comment);
List<GenrricStoring> values = dbconnection.getAllComments();
//updating the content on the screen
this.adapter = new UserItemAdapter(this, android.R.layout.simple_list_item_1, values);
listView.setAdapter(adapter);
}
else
{
int duration = Toast.LENGTH_SHORT;
//for showing nothing is left in the list
Toast toast = Toast.makeText(getApplicationContext(),"Db is empty", duration);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
i created custom listview with text and two buttons, i set up arraylist and adapter but my listview is showing every element as last, for ex. if i add 3 elements: "text1","text2","text3" my listview shows "text3", "text3" "text3" and i dont have any idea why.
private ListView lista;
private List<Piosenka> listaPiosenek;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (EditText) findViewById(R.id.editText1);
lista = (ListView) findViewById(R.id.listView1);
lista.setClickable(true);
}
public void update_listy() throws MalformedURLException, IOException
{
final List<Piosenka> listaPiosenek = new ArrayList<Piosenka>();
listaPiosenek.add(new Piosenka("text1"));
listaPiosenek.add(new Piosenka("text2"));
listaPiosenek.add(new Piosenka("text3"));
PiosenkaAdapter adapter = new PiosenkaAdapter(this, listaPiosenek);
lista.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long index)
{
System.out.println("sadsfsf");
}
});
lista.setAdapter(adapter);
}
Edit: PiosenkaAdapter code
public class PiosenkaAdapter extends BaseAdapter implements OnClickListener {
private Context context;
private List<Piosenka> listapiosenek;
public PiosenkaAdapter(Context context, List<Piosenka> listapiosenek) {
this.context = context;
this.listapiosenek = listapiosenek;
}
public int getCount() {
return listapiosenek.size();
}
public Object getItem(int position) {
return listapiosenek.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup viewGroup) {
Piosenka element = listapiosenek.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.listview_element, null);
}
TextView tvTytul = (TextView) convertView.findViewById(R.id.tvTytul);
tvTytul.setText(Piosenka.getTytul());
Button btnPobierz = (Button) convertView.findViewById(R.id.btnPobierz);
btnPobierz.setFocusableInTouchMode(false);
btnPobierz.setFocusable(false);
btnPobierz.setTag(element);
Button btnPlay = (Button) convertView.findViewById(R.id.btnPlay);
btnPlay.setFocusableInTouchMode(false);
btnPlay.setFocusable(false);
btnPlay.setOnClickListener(this);
btnPlay.setTag(element);
// btnRemove.setId(position);
return convertView;
}
#Override
public void onClick(View view) {
switch(view.getId()){
case R.id.btnPobierz:
Piosenka entry = (Piosenka) view.getTag();
listapiosenek.remove(entry);
notifyDataSetChanged();
break;
case R.id.btnPlay:
entry = (Piosenka) view.getTag();
listapiosenek.remove(entry);
notifyDataSetChanged();
break;
}
}
}
Try this...
lista.setAdapter(adapter);
adapter.notifyDataSetChanged();
Can you paste you PiosenkaAdapter's code?
I don't know your language, but the Piosenka variable is fetched correctly in getView()
Piosenka element = listapiosenek.get(position);
But this looks strange to me
TextView tvTytul = (TextView) convertView.findViewById(R.id.tvTytul);
tvTytul.setText(Piosenka.getTytul());
Piosenka.getTytul() looks to me as a static method call, where you should do a regular method call to element.getTytul() instead.