I want to get data from database and show this data into a custom listview. I have made a custom list view with two textviews and I have an id autoincremented and name and a value in a database.
I want to display that name and the value in the custom listview textview. I am new in Android.
public class List_View_Data extends AppCompatActivity {
database db;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list__view__data);
db=new database(this);
show_data_sql();
}
private void show_data_sql(){
listView= (ListView) findViewById(R.id.activity_list__view__data);
ArrayList<String> thelist=new ArrayList<>();
Cursor data=db.show_data();
if(data.getCount()==0){
Toast.makeText(this,"Data Not Found",Toast.LENGTH_LONG).show();}
else{
while (data.moveToNext()){
thelist.add(data.getString(1));
thelist.add(data.getString(2));
}
//BaseAdapter is a very generic adapter that allows you to do pretty much whatever you want.
//using baseadapter which have listadapter and spinneradapter
Adapter listAdapter=new Adapter(this,data);
{
listView.setAdapter(listAdapter);
}
}
}
}