i have an activity with some buttons in which when you click on any of buttons First with Intent send a value to another activity that contains a list view is filled with database. And I want to use this value as a parameter for where command select for filling list view with special Content
now i have a problem that when run program and when click on a button, first open a empty list view and after clicking back-button, list view is correctly displayed data.
Where is my mistake?
source MainActivity
final Intent i = new Intent(MainActivity.this,ListActivity.class);
btn_irani.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
i.putExtra("position","ایران");
startActivity(i);
startActivity(GoToList);
}
});
btn_turkie.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
i.putExtra("position","ترکیه");
startActivity(i);
startActivity(GoToList);
}
});
source ListActivity
public class ListActivity extends Activity {
String value = "";
MovieDB myDbHelper;
SQLiteDatabase db;
ListAdapter adapter;
ArrayList<HashMap<String, String>> data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
value = getIntent().getStringExtra("position");
ListView lst=(ListView) findViewById(R.id.listView1);
Load_Database();
db = myDbHelper.getReadableDatabase();
Cursor c = db.rawQuery("select * from movie_list where product = '"+value+"'", null);
data = new ArrayList<HashMap<String, String>>();
for (; c.moveToNext();) {
HashMap<String, String> map = new HashMap<String, String>();
String img = c.getString(c.getColumnIndex("img"));
String name = c.getString(c.getColumnIndex("name"));
map.put("img", img);
map.put("name", name);
data.add(map);
}
adapter = new ListMovie(this, data);
lst.setAdapter(adapter);
}
Please Help me!