ArrayAdapter<T>(Context context, int textViewResourceId);
上下文,布局文件
ArrayAdapter<T>(Context context, int resource, int textViewResourceId);
上下文,显示的视图,显示视图的组件
ArrayAdapter<T>(Context context, int textViewResourceId, List<T> objects)
上下文,显示的视图,数据资源(对象)
ArrayAdapter<T>(Context context,int textViewResourceId,T[] objects)
上下文,显示的视图,数据资源(数组)
ArrayAdapter<T>(Context context,int resource,int textViewResourceId, List<T> objects)
上下文,显示的视图,显示视图的组件,数据资源(数组)
ArrayAdapter<T>(Context context,int resource,int textViewResourceId, T[] objects)
上下文,显示的视图,显示视图的组件,数据资源(数组)
public List<String> findAllNames() { List<String> names = new ArrayList<String>(); SQLiteDatabase db = dh.getWritableDatabase(); Cursor c = db.rawQuery("select username from users", null); while (c.moveToNext()) { names.add(c.getString(c.getColumnIndex("username"))); } db.close(); return names; }
package com.example.android_sqlite; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import com.example.android_sqlite.dao.impl.UserDaoImpls; import com.example.android_sqlite.database.DatabaseHelper; /** * ArrayAdapter * @author zhaoyazhi * */ public class MainActivityss extends Activity implements OnItemClickListener { private ListView lv_users;// 视图层 // model层 相关的对象的声明 private DatabaseHelper dh; private UserDaoImpls userDao; private List<String> names; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 创建数据库 dh = new DatabaseHelper(this); // 获取显示数据 model userDao = new UserDaoImpls(dh); // 查询获取数据 names = userDao.findAllNames(); // 设置视图层 lv_users = (ListView) findViewById(R.id.lv_users); //参数1:上下文 参数2:显示的视图 参数3:数据资源 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,names); // adapter作为控制层 lv_users.setAdapter(adapter); // 注册点击事件 lv_users.setOnItemClickListener(this); } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long arg3) { // 获取点击我的数据 Toast.makeText(this, parent.getItemAtPosition(position) + "", 0).show(); } }
赵雅智_ListView_ArrayAdapter,布布扣,bubuko.com
原文:http://blog.csdn.net/zhaoyazhi2129/article/details/28711021