I would like to ask a question: I have a ListView
, where your adapter is clarified in the same activity and the contents of adapter (the strings ) are in another class, in another package. How do I delete a specific item from ListView
, in the same code, without user interaction? (for example, an application update where an item will no longer appear).
In the case I am studying, the user will click on an item of listView
, and a text inside the activity will be filled with the string that is in otherClass.lista
and depending on the clicked position , a different text will appear.
EDITED
The following click action on the ListView:
ListView listView = (ListView) findViewById(R.id.lista);
listView.setAdapter(new listAdapter(this));
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
nome.setText(otherClass.string.get(position));
}
});
Here's the Adapter I'm using:
public class listAdapter extends BaseAdapter implements ListAdapter {
public Context context;
public ArrayList<String> lug;
public Typeface fonte;
public listAdapter(Context context) {
lug = otherClass.string;
this.context = context;
}
@Override
public int getCount() {
return lug.size();
}
@Override
public Object getItem(int position) {
return lug[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView title = new TextView(context);
title.setText(lug.get(position));
title.setTextSize(18);
return title;
}
}
Now follows the Array in the class that is in another package
public class otherClass {
public static ArrayList<String> string = new ArrayList<String>();{
string.add("primeiro item");
string.add("Segundo item");
}
}
The current issue is that the ArrayList items above are not being printed ... and I would like to know (when I can print the items) how to delete the items.
The intention, as the images follow, would be that in otherClass
have the items that will appear in listView
and clicking on some item, the respective information of the item will be clicked (these declared in the same class so as not to be confused all separated). More items will be added to each application update, so it needs to be a dynamic and organized mode. Ideas? (since Strings does not seem to be a good way)