I have two layouts for a single activity that I will dynamically change the layout. Here the null pointer occurs at the line.
I tried to change the view from layout 1 to layout 2
listview.setadapter(listviewAdapter)
lv2.setAdapter(lva);
The error I am getting is
java.lang.NullPointerException at in.prasilabs.eagleeye.Log$DBSync.onPostExecute(Log.java:170)
public class Log extends Activity {
ListView lv1;
ListView lv2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logmenu);
lv1 = (ListView) findViewById(R.id.listView1);
final Activity act = getParent();
String[] menu = new String[]
{
"Last 10 log",
"All logs (100)",
};
ArrayAdapter<String> menuadapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,android.R.id.text1, menu);
lv1.setAdapter(menuadapter);
lv1.setOnItemClickListener(new OnItemClickListener() {
DBSync dbs;
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
dbs = new DBSync(position, Log.this, act);
dbs.execute();
break;
default:
break;
}
}
});
}
class DBSync extends AsyncTask<String, Void, Void> {
int q;
String[] time = new String[]{"No logs"};
String[] status = new String[]{"closed"};
Context cnt;
Activity act;
public DBSync(int qu, Log lg, Activity ac) {
q = qu;
cnt = lg;
act = ac;
}
#Override
protected Void doInBackground(String... params) {
return null;
}
#Override
protected void onPostExecute(Void result) {
//setContentView(R.layout.log);
time = new String[]{"hii","yes"};
status = new String[]{"no", "yes"};
boolean isFirstXml=true;//evaluatingConditionFunction();
LayoutInflater inflator=getLayoutInflater();
View view=inflator.inflate(isFirstXml?R.layout.logmenu:R.layout.log, null, false);
view.startAnimation(AnimationUtils.loadAnimation(cnt, android.R.anim.slide_out_right));
**setContentView(view);**
lv2 = (ListView) findViewById(R.id.listView2);
ListViewAdapter lva = new ListViewAdapter(act, time, status);
**lv2.setAdapter(lva);**
lv2.refreshDrawableState();
}
}
}
You are calling setContentView twice.
setContentView(R.layout.log);
setContentView(R.layout.logmenu);
By calling it twice, only the second one (R.layout.logmenu) will be set. I guess R.id.listView2 is in R.layout.log. Because of this, (ListView) findViewById(R.id.listView2) returns null and lv2 gets null. When you try to call lv2.setAdapter, you try to set an adapter on an object that is null - Your app crashes.
Related
I have two spinners, the first one shows the transport lines and the second one shows the stations of the line selected on the first spinner, the problem is that I want to set to empty value the second spinner when I click on the first one, but I can't do it.
private ArrayAdapter<String> arrayAdapter;
private MaterialBetterSpinner spinner;
private ArrayAdapter<String> arrayAdapter2;
private MaterialBetterSpinner spinner2;
I've tried a few options on the onItemClick() method of the first spinner but it's not working propertly:
spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
#Override
protected void onPreExecute() {
// I'm trying all the options in this method
}
#Override
protected String[] doInBackground(String... strings) {
}
#Override
protected void onPostExecute(String[] result) {
}
}
});
Option 1:
arrayAdapter2.clear();
arrayAdapter2.notifyDataSetChanged();
Option 2:
spinner2.setAdapter(null);
Option 3:
ArrayList<String> list = new ArrayList<>();
list.add("");
spinner2.setSelection(list.size()-1);
Option 4:
arrayAdapter2.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
spinner2.setAdapter(arrayAdapter2);
spinner2.setSelection(arrayAdapter2.getCount());
spinner2.setOnItemSelectedListener(this);
arrayAdapter2.notifyDataSetChanged();
To sum up, there is a way to change the value of a spinner in function of the value of other one? Or just a way to change the value of a spinner to empty value?
Any help will be apreciated!
Use setOnItemSelectedListener instead of OnItemClickListener like:
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
{
if(pos==0) // you can change condition as per your requirement
{
arrayAdapter2.clear();
arrayAdapter2.notifyDataSetChanged();
}
}
public void onNothingSelected(AdapterView<?> parent)
{
}
});
The complete code:
public class FillTransportPlaceActivity extends AppCompatActivity {
private ArrayAdapter<String> arrayAdapter;
private MaterialBetterSpinner spinner;
private ArrayAdapter<String> arrayAdapter2;
private MaterialBetterSpinner spinner2;
private ArrayList<String> list = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fill_transport_place);
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
spinner = findViewById(R.id.listLines);
spinner.setAdapter(arrayAdapter);
arrayAdapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
spinner2 = findViewById(R.id.listStations);
spinner2.setAdapter(arrayAdapter2);
SharedPreferences sp = getApplicationContext().getSharedPreferences("transportButton", 0);
boolean metro = sp.getBoolean("metro", false);
boolean bus = sp.getBoolean("bus", false);
spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(parent.getItemAtPosition(position).toString() != null) {
String choice = parent.getItemAtPosition(position).toString();
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB)
new stationsDB().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, choice);
else
new stationsDB().execute(choice);
}
}
});
}
private class stationsDB extends AsyncTask<String, String[], String[]> {
#Override
protected String[] doInBackground(String... strings) {
return DB_transportPlace.getStations(strings[0]);
}
#Override
protected void onPostExecute(String[] result) {
updateAdapter2(result);
}
}
public void updateAdapter(String[] result) {
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, result);
spinner.setAdapter(arrayAdapter);
}
public void updateAdapter2(String[] result) {
arrayAdapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, result);
spinner2.setAdapter(arrayAdapter2);
}
As I said I've tried with setOnItemSelectedListener instead of OnItemClickListener and it didn't work, only execute one time in the onCreate method, I just want to change the value of spinner2 to empty when I change the value of spinner1.
I implemented a custom list view using customadapter. When I press on refresh button, the data is fetched from database and updated in list view. But in my case the items get appended after the previous items i.e. if i have 2 items in databse and I press refresh button without changing the database items,the same items gets appended and 4 listitems get displayed. Quick help required. notifyDatasetChanged() is used in code. But I don't know if it's correct.
Here is code for MainActivity.java
public class MainActivity extends Activity {
ListView lv;
TextView tv1,tv2,tv3;
ArrayList<String> a=new ArrayList<String>();
ArrayList<String> b=new ArrayList<String>();
ArrayList<String> c=new ArrayList<String>();
ArrayList<String> d=new ArrayList<String>();
String mydata,name,name1,society,date,venue;
public String[] s1 = new String[50];
public String[] s2=new String[50];
public String[] s3=new String[50];
public String[] s4=new String[50];
public int[] img = {R.drawable.rty, R.drawable.sf, R.drawable.rty};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1=(TextView)findViewById(R.id.textView);
lv = (ListView) findViewById(R.id.listView);
ConnectionDetector cd = new ConnectionDetector(getApplicationContext());
Boolean isInternetPresent = cd.isConnectingToInternet(); // true or false
if(isInternetPresent) {
new MyData().execute();
}
else
Toast.makeText(MainActivity.this,"No Internet Connection",Toast.LENGTH_SHORT).show();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent in = new Intent(MainActivity.this, listclick.class);
in.putExtra("position", position);
startActivity(in);
}
});
}
public void abc(View v)
{
Intent in=new Intent(MainActivity.this,webform.class);
startActivity(in);
}
public void ref(View v)
{
ConnectionDetector cd = new ConnectionDetector(getApplicationContext());
Boolean isInternetPresent = cd.isConnectingToInternet();
if(isInternetPresent) {
new MyData().execute();
}
else
Toast.makeText(MainActivity.this,"No Internet Connection",Toast.LENGTH_SHORT).show();
}
public class MyData extends AsyncTask<String,String,String>
{
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
CustomAdapter cad = new CustomAdapter(MainActivity.this, s1, img,s2,s3,s4);
lv.setAdapter(cad);
cad.notifyDataSetChanged();
}
#Override
protected String doInBackground(String... params) {
getData();
return null;
}
}
public void getData()
{
try {
HttpClient httpClient=new DefaultHttpClient();
HttpPost httpPost=new HttpPost("http://collegeevents.esy.es/abc.php");
HttpResponse response=httpClient.execute(httpPost);
HttpEntity httpEntity=response.getEntity();
InputStream is=httpEntity.getContent();
BufferedReader reader=new BufferedReader(new InputStreamReader(is,"utf-8"),8);
StringBuilder strbuilder=new StringBuilder();
String line=null;
while ((line=reader.readLine())!=null)
{
strbuilder.append(line);
}
is.close();
mydata=strbuilder.toString();
JSONArray obj=new JSONArray(mydata);
for(int i=0;i<obj.length();i++)
{
JSONObject obj1=obj.getJSONObject(i);
a.add(i,obj1.getString("Name"));
b.add(i,obj1.getString("society"));
c.add(i,obj1.getString("venue"));
d.add(i,obj1.getString("date"));
}
String[] s = new String[a.size()];
s=a.toArray(s);
s1 = s;
String[] soc = new String[b.size()];
soc=b.toArray(soc);
s2 = soc;
String[] ven = new String[c.size()];
ven=c.toArray(ven);
s3 = ven;
String[] dat = new String[d.size()];
dat=d.toArray(dat);
s4 = dat;
}
catch (Exception e)
{
}
}
}
Here is CustomAdapter.java
public class CustomAdapter extends ArrayAdapter<String> {
Context c1;
String s1[],soc[],ven[],dat[];
int s2[];
CustomAdapter(Context c,String s[],int s3[],String society[],String venue[],String date[])
{
super(c, R.layout.listcustom, s);
this.c1=c;
this.s1=s;
this.s2=s3;
this.soc=society;
this.ven=venue;
this.dat=date;
}
#Override
public View getView(int position, View v, ViewGroup parent) {
LayoutInflater li=(LayoutInflater) c1.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=li.inflate(R.layout.listcustom,parent,false);
TextView tv=(TextView)v.findViewById(R.id.textView);
TextView tv1=(TextView)v.findViewById(R.id.society);
TextView tv2=(TextView)v.findViewById(R.id.venue);
TextView tv3=(TextView)v.findViewById(R.id.date);
tv.setText(s1[position]);
tv1.setText(soc[position]);
tv2.setText(ven[position]);
tv3.setText(dat[position]);
if(position%2==0) {
tv.setTextColor(Color.parseColor("#01579B"));
tv3.setTextColor(Color.parseColor("#01579B"));
}
else{
tv.setTextColor(Color.parseColor("#00897B"));
tv3.setTextColor(Color.parseColor("#00897B"));
}
v.setTag(position);
//notifyDataSetChanged();
return v;
}
}
I finally got it. The short answer for you question — you are not clearing a, b, c, d ArrayLists. So each getData() call adds data while previous data is still there. So, you should add a.clear(), b.clear() ... etc. at the start of getData.
However i would suggest to make the following improvements:
Introduce entity for adapter data. This entity will contain 4 fields: name, society, venue, date.
Thus you don't need to use 4 arrays and 4 ArrayLists. For convience i will use "Event" as entity name. This will lok something like:
AsyncTask:
public class MyData extends AsyncTask<String, String, Event[]> {
#Override
protected Event[] doInBackground(String... params) {
return getData();
}
#Override
protected void onPostExecute(Event[] s) {
cad.clear();
cad.addAll(s)
}
}
Activity:
public class MainActivity extends Activity {
private CustomAdapter cad;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
lv = (ListView) findViewById(R.id.listView);
cad = new CustomAdapter(getApplicationContext());
}
}
CustomAdapter:
public class CustomAdapter extends ArrayAdapter<Event> {
private final LayoutInflater inflater;
public CustomAdapter(Context c, Event ev[]) {
super(context, ev[]);
inflate = LayoutInflater.from(context);
}
CustomAdapter(Context c) {
this(context, new Event[0]);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final View v;
if(convertView == null) {
v = inflater.inflate(...)
} else {
v = convertView;
}
// find views or event better — use ViewHolder pattern
Event evt = getItem(position);
tv.setText(evt.getName());
...
return v;
}
}
Don't use onClick tag. Use view#setOnClickListener instead. onClick binds layout and activity implementation and that's not good.
Use clear names. Something like LoadDataTask instead of MyData.
so, i working on a listview in a fragment...
the "onItemClick" doesnt work, but the onItemLongClick and the refresh works well..
(using SherlockLibary...)
here is my code:
public static class MyListActivity extends SherlockListFragment
implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener,OnRefreshListener {
ArrayList<article> items2;
private String[] articles = {"x","y","z"}; //articles titles
private String[] Dates = {"20:12"
, "18:20"
, "15:15"
, "14:11"
, "10:00"
}; //articles dates
private Site[] Sites = {
Site.Ynet
, Site.bla
, Site.blabla
, Site.blablabla
, Site.blablabla
}; //articles Gender
private void initData() {
items2 = new ArrayList<article>();
for (int i = 0; i < 5; i++) {
items2.add(new article(articles[i], Dates[i], Sites[i]));
}
}
private PullToRefreshLayout mPullToRefreshLayout;
ListView list;
MyArrayAdapter adapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main, container, false);
mPullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.listlay);
ActionBarPullToRefresh.from(getActivity())
.allChildrenArePullable()
.listener(this)
.setup(mPullToRefreshLayout);
initData();
list = (ListView)view.findViewById(android.R.id.list);
adapter = new MyArrayAdapter(getActivity(), items2);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
list.setOnItemLongClickListener(this);
return view;
}
// Handle click on an item (displays it in a Toast)
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
items2.remove(position);
Toast.makeText(getActivity(), "select: " + items2.get(position).toString(), Toast.LENGTH_LONG).show();
}
// Handle a long click on an item (deletes it)
#Override
public boolean onItemLongClick(AdapterView<?> parent, View v,
int position, long id) {
Toast.makeText(getActivity(),
"del: " + items2.get(position).toString(),
Toast.LENGTH_LONG).show();
items2.remove(position);
adapter.notifyDataSetChanged(); // Update the ListView
return true; // i.e. all ended well
}
#Override
public void onRefreshStarted(View view) {
/**
nathing here yet...
* Simulate Refresh with 4 seconds sleep
*/
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(Constants.SIMULATED_REFRESH_LENGTH);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Notify PullToRefreshLayout that the refresh has finished
mPullToRefreshLayout.setRefreshComplete();
}
}.execute();
}
}
any idea what can i do with it?
i tried a lot but nathing works.... help please....
i tried the to add list.setItemsCanFocus(false); or android:focusable="false"
or a ndroid:clickable="false" ...
doesnt work...
onItemClick() method won't work if the items of ListView is focusable. Check your item xml to see if you have set these for any of its element.
android:focusable="true"
or
android:clickable="true"
Another soulution: Use this line
list.setItemsCanFocus(false);
after
list = (ListView)view.findViewById(android.R.id.list);
here I have a Fragment, I use this code and everything works normally, and what I want to do is update my shown list if there is a new file, could you guys give any advice or hint?
CODE:
public class HomeFragment extends Fragment {
public static final String TITLE = "title";
private List<String> library = new ArrayList<String>();
private TextView tv;
private ListView lv;
private ArrayAdapter<String> adapter;
public static Handler handHF;
private String[] temp;
private Object UIlock = new Object();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.home_fragment, container,
false);
library = getLibraryList();
if (!library.isEmpty()) {
if (tv != null) {
tv.setVisibility(View.GONE);
} else {
temp = library.toArray(new String[library.size()]);
lv = (ListView) rootView.findViewById(R.id.library_list);
adapter = new ArrayAdapter<String>(rootView.getContext(),
android.R.layout.simple_list_item_1, temp);
lv.setAdapter(adapter);
setListener(lv);
tv = (TextView) rootView.findViewById(R.id.library_tv1);
tv.setVisibility(View.GONE);
tv = null;
}
} else {
tv = (TextView) rootView.findViewById(R.id.library_tv1);
tv.setText("No Manga found...");
}
return rootView;
}
#SuppressLint("HandlerLeak")
#Override
public void onResume() {
/*
* Fragment on pause state
*/
super.onResume();
handHF = new Handler(Looper.getMainLooper()) {
#Override
public void handleMessage(Message msg) {
if (msg.what == 0) {
refreshAdapter();
}
}
};
}
private void setListener(ListView lv) {
/*
* Sets listener on listView
*/
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent myIntent = new Intent(view.getContext(),
ChapterActivity.class);
myIntent.putExtra(TITLE, parent.getItemAtPosition(position)
.toString());
startActivity(myIntent);
}
});
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(view.getContext(),
parent.getItemAtPosition(position).toString(),
Toast.LENGTH_SHORT).show();
return true;
}
});
}
private final List<String> getLibraryList() {
/*
* Returns List<String> of library
*/
List<String> l = new ArrayList<String>();
File dir = new File(Constants.UNDUH);
if (dir.exists()) {
File[] dirs = dir.listFiles();
for (File i : dirs) {
l.add(i.getName());
}
return l;
} else {
return l;
}
}
private void refreshAdapter() {
/*
* It will update library and
*/
synchronized (UIlock) {
getActivity().runOnUiThread(new Runnable() {
public void run() {
if (tv != null) {
tv.setVisibility(View.GONE);
}
library = getLibraryList();
temp = library.toArray(new String[library.size()]);
lv = (ListView) getActivity().findViewById(
R.id.library_list);
adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, temp);
lv.setAdapter(adapter);
}
});
}
}
}
any advice will be appreciated, thank you!
Update your list of string which you are passing to the ListView in your case you are using
private String[] temp;
Use notifyDataSetChanged Method, just call this after your adapter and it will automatically adds more items to list if your temp[] increments.
like this
adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, temp);
lv.setAdapter(adapter);
adapter.notifyDataSetChanged();
Where you are adding more data into temp[]
add an extra line
((ArrayAdapter) lv.getAdapter()).notifyDataSetChanged();
I have a problem with my listview that when I add a task to my database, I need to update my listview with this new added task....
I'm new to android and Eclipse...
Here is my code for Main (that shows the ListView)
public class Main extends ListActivity {
Button newCat;
TextView todaytaskId;
ResultDatabase controller5 = new ResultDatabase(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
newCat = (Button) findViewById(R.id.bNewCat);
newCat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent nextScreen = new Intent(getApplicationContext(),
CategoryList.class);
startActivity(nextScreen);
}
});
ArrayList<HashMap<String, String>> todaytaskList = controller5
.getTodayTasks();
if (todaytaskList.size() != 0) {
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
todaytaskId = (TextView) view
.findViewById(R.id.todaytaskId);
String valtaskId = todaytaskId.getText().toString();
Intent objIndent = new Intent(getApplicationContext(),
DelayTask.class);
objIndent.putExtra("todaytaskId", valtaskId);
startActivity(objIndent);
}
});
SimpleAdapter adapter = new SimpleAdapter(Main.this, todaytaskList,
R.layout.view_today_task, new String[] { "taskId",
"taskName", "taskTime" }, new int[] {
R.id.todaytaskId, R.id.todaytasktv,
R.id.todaytasktimetv});
lv.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
}
Here's my code to select tasks from ResultDatabase class
public ArrayList<HashMap<String, String>> getTodayTasks() {
ArrayList<HashMap<String, String>> wordList;
wordList = new ArrayList<HashMap<String, String>>();
String selectQuery = "SELECT * FROM tasks where taskDate = date('now') AND taskDone = 'No'";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
HashMap<String, String> map = new HashMap<String, String>();
map.put("taskId", cursor.getString(0));
map.put("taskName", cursor.getString(1));
map.put("taskTime", cursor.getString(3));
// map.put("taskDate", cursor.getString(4));
wordList.add(map);
} while (cursor.moveToNext());
}
return wordList;
}
After modifying the data set that is connected on the adapter you must call notifyDataSetChanged to notify the adapter to update the views with the new data. You must also call requery on the Cursor to update the cursor with new data. To clarify you should call requery before notifyDataSetChanged.
Check sample code below
public class WeatherAppActivity extends ListActivity {
Button buton;
ItemsAdapter lista;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List<String> initialList = new ArrayList<String>();
initialList.add("Bucuresti");
initialList.add("Sibiu");
lista=new ItemsAdapter(this, initialList);
buton=(Button)findViewById(R.id.button1);
buton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
lista.add(""+System.currentTimeMillis()); // e chiar getText()
lista.notifyDataSetChanged();
}
});
setListAdapter(lista);
}
class ItemsAdapter extends ArrayAdapter<String> {
public ItemsAdapter(Context context, List<String> list) {
super(context, R.layout.lista, list);
}
#Override
public View getView(final int position, View row, final ViewGroup parent) {
final String item = getItem(position);
ItemWrapper wrapper = null;
if (row == null) {
row = getLayoutInflater().inflate(R.layout.lista, parent, false);
wrapper = new ItemWrapper(row);
row.setTag(wrapper);
} else {
wrapper = (ItemWrapper) row.getTag();
}
wrapper.refreshData(item);
return row;
}
class ItemWrapper {
TextView text;
public ItemWrapper(View row) {
text = (TextView) row.findViewById(R.id.elementLista);
}
public void refreshData(String item) {
text.setText(item);
}
}
}
}