Android 试图用数据库映像填充listview
我试图用姓名、电话、id和图像填充listview(id未显示,仅当我单击所需的客户端时才提供,播放另一个活动,请求通过id找到的信息),我试图用与我的问题相关的其他帖子增加代码,但没有成功,有人能帮助我吗?我不是一个程序员,我只是想把更多的东西作为一种爱好来学习,到目前为止我所拥有的 java(在数据库中搜索信息的代码)Android 试图用数据库映像填充listview,android,image,listview,Android,Image,Listview,我试图用姓名、电话、id和图像填充listview(id未显示,仅当我单击所需的客户端时才提供,播放另一个活动,请求通过id找到的信息),我试图用与我的问题相关的其他帖子增加代码,但没有成功,有人能帮助我吗?我不是一个程序员,我只是想把更多的东西作为一种爱好来学习,到目前为止我所拥有的 java(在数据库中搜索信息的代码) public List getAllClients(){ 列表=新的ArrayList(); String selectQuery=“按nome ASC从userDB订单中选
public List getAllClients(){
列表=新的ArrayList();
String selectQuery=“按nome ASC从userDB订单中选择*”;
SQLiteDatabase db=this.getReadableDatabase();
Cursor Cursor=db.rawQuery(selectQuery,null);
if(cursor.moveToFirst()){
做{
list.add(cursor.getString(2));
}while(cursor.moveToNext());
}
cursor.close();
db.close();
退货清单;
}
MainActivity.java(具有适配器)
private void客户端列表(){
DataSource db=新数据源(getApplicationContext());
List clientlist=db.getAllClients();
clientAdapter=new ArrayAdapter(这个,android.R.layout.simple_list_item_1,android.R.id.text1,clientlist);
setAdapter(clientAdapter);
}
content_main.xml(包含一个searchview和一个listview)
我发现,为了做我想做的事情,我必须有一个自定义的listview,所以应该是这样
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="8dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/perfil_image_cliente"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/perfil_image" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/nome_lista_client"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginStart="0dp"
android:layout_marginTop="5dp"
android:text="Nome: "
android:textColor="#008080"
android:textSize="24sp" />
<TextView
android:id="@+id/fone_lista_client"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginStart="0dp"
android:layout_marginTop="5dp"
android:text="Fone: "
android:textColor="@color/common_google_signin_btn_text_dark_focused"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
如果
getAllClients()
返回任何内容,请使用调试器检查
如果没有,请检查数据库中是否有内容,以及您的查询是否正确
如果
getAllClients()
返回了一些内容,那么列表实现存在问题,请检查问题到底是什么?发生了什么/应该发生什么?没有显示任何内容吗?在代码中,我知道填充信息,我不知道如何将其他信息一起填充,更不知道如何填充图像,除了从数据库中提取图像外,我还必须解码并将其放入ImageView中。在代码中,我知道填充信息,我不知道如何将其他信息一起填充,更不知道如何将图像填充到一起,除了从数据库中提取图像外,我还必须解码并放入imageview中
private void ClientList() {
DataSource db = new DataSource(getApplicationContext());
List<String> clientlist = db.getAllClients();
clientAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, clientlist);
clientList.setAdapter(clientAdapter);
}
<SearchView
android:id="@+id/searchView"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:queryHint="@string/search"
android:iconifiedByDefault="false"
android:background="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchView" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="8dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/perfil_image_cliente"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/perfil_image" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/nome_lista_client"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginStart="0dp"
android:layout_marginTop="5dp"
android:text="Nome: "
android:textColor="#008080"
android:textSize="24sp" />
<TextView
android:id="@+id/fone_lista_client"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginStart="0dp"
android:layout_marginTop="5dp"
android:text="Fone: "
android:textColor="@color/common_google_signin_btn_text_dark_focused"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>