Hi all!
I'm doing an admin page that can view the users that exist in the system. My idea is to show a list of the users and the details in one page. I heard that using listview is very tedious. Is there any other way that is easy?
Maybe view in textview but I dont know how it works. I must put in a lot of textview on my xml?
A simple task that I need to know how to do. I just need to know how to view datas in a page, using any method.
Thank you very much! Hope to get responds soooon! =D
Dayne
Hello again
Here's how a listview looks like:
package log1.log2;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class AdminMain extends ListActivity {
static final String[] COUNTRIES = new String[] {
"Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands","Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
For the code above, the data is written in the codes itself. My data is in my database and I need it to be shown on the listview. I do not know how to do it. I tried a few ideas I had:
public class AdminMain extends ListActivity {
DBAdapter db = new DBAdapter(this);
private String TEST;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db.open();
Cursor c = (Cursor) db.getAllUser();
final String[] COUNTRIES = new String[] {
};
TEST=c.getString(1).toString();
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, TEST));
getListView().setTextFilterEnabled(true);
}
}
I declare a string and I tried retrieving data from database and save it to the string which is TEST. And then I tried showing it on the listview :
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, TEST));
getListView().setTextFilterEnabled(true);
But I cant put 'TEST' in the listview. The error, The constructor ArrayAdapter<String>(AdminMain, int, String) is undefined.
will appear.
I hope somebody will give me a good answer for this. I'm looking forward to your replies. Thank you for taking your time reading this.
-Dayne
Hello Sephy
Here's what I edited.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db.open();
Cursor c = (Cursor) db.getAllUser();
/*final String[] COUNTRIES = new String[] {
};*/
final String[] TEST = c.getString(1);
//TEST[]=c.getString(1).toString();
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1));
getListView().setTextFilterEnabled(true);
}
As you can see I tried to put data from my database straight into the array but it can't work; final String[] TEST = c.getString(1);
. The error message Type mismatch: cannot convert from String to String[]
appeared.