It is necessary to display a list from the database in the format simple_list_item_2 . In this system layout there are two textview . An application using this layout crashes. However, if you use your own layout , which contains one textview , the application starts and displays everything, but of course not in the right format. I understand that it is necessary to prescribe somehow that from the ArrayList 'resulting from the database, one field corresponds to the 1st textview , and another field the 2nd textview from the simple_list_item_2 . Saw examples with redefinition, but the class is used there, and I have a DB. Please tell me how to solve such problems.
public class IdevOwnSqliteDbActivity extends ListActivity { private static final String DB_NAME = "yourdb.sqlite3"; private static final String TABLE_NAME = "friends"; private static final String FRIEND_ID = "_id"; private static final String FRIEND_NAME = "name"; private static final String FRIEND_POEM = "poem"; private SQLiteDatabase database; private ListView listView; private ArrayList<String> friends; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ExternalDbOpenHelper dbOpenHelper = new ExternalDbOpenHelper(this, DB_NAME); database = dbOpenHelper.openDataBase(); fillFreinds(); setUpList(); } private void setUpList() { setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, friends)); //R.layout.my_list, friends)); listView = getListView(); listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position,long id) { Toast.makeText(getApplicationContext(), ((TextView) view).getText() + " could be iDev's friend", Toast.LENGTH_SHORT).show(); } }); } private void fillFreinds() { friends = new ArrayList<String>(); Cursor friendCursor = database.query(TABLE_NAME, new String[] {FRIEND_ID, FRIEND_NAME, FRIEND_POEM}, null, null, null, null , FRIEND_NAME); friendCursor.moveToFirst(); if(!friendCursor.isAfterLast()) { do { String name = friendCursor.getString(1); String poem = friendCursor.getString(2); friends.add(name); friends.add(poem); } while (friendCursor.moveToNext()); } friendCursor.close(); } }