I have a List View in a page and inside the ListView on click on a button I want to reload the page with new set of data on it.
package com.examples.listzones;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MyActivity extends Activity implements
AdapterView.OnItemClickListener, View.OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView list = new ListView(this);
setContentView(list);
String[] items = { "Tom", "Sally", "Bill", "John", "Santiago", "Isabella" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.review, R.id.textView1, items) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
View text = row.findViewById(R.id.seemore);
text.setTag(position);
text.setOnClickListener(MyActivity.this);
return row;
}
};
list.setAdapter(adapter);
list.setOnItemClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.seemore:
// RELOAD THE PAGE WITH NEW SET OF DATA
break;
default:
break;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(this, "Item Click " + position, Toast.LENGTH_SHORT).show();
}
}
Inside OnClick I want to load the page with new dataset.
You do not have to restart the Activity. You can put the new data into the adapter and notify the adapter, that the dataset has been changed.
adapter.clear();
adapter.addAll("new 1"," new 2","new 3");
adapter.notifyDataSetChanged();