【问题标题】:How to show SQLite data in ListView in android? search business app如何在 Android 的 ListView 中显示 SQLite 数据?搜索业务应用
【发布时间】:2014-05-04 23:52:55
【问题描述】:

我是 Java 编程和这个网站的新手。这是我的第二个程序,但我坚持让 SQLite 数据显示在 ListView 项目中。我的程序正在显示业务范围,然后详细显示所选业务,抱歉我不能发布照片。

我得描述一下……

首先,ListView 业务列表: 每个 ListView 项中有 2 个单元格。 左边的单元格有企业照片,右边的单元格有 3 个信息:企业名称(如粗体,大文本)、地址(小文本,可选)和评级(5 星)

二、精选业务详解:

在整页详细显示所选业务。 左上角单元格是照片,右上角单元格与 ListView 具有相同的信息,它在顶部单元格下显示描述、联系信息和地图。

我想在 listView 中显示企业名称和地址以及评级,并且数据必须来自 SQLite。我该怎么做?请帮我。提前致谢!!!我已经尝试了以下代码,但它没有工作。

public class ListViewItems extends Activity {

TextView textViewHotClubs;
Button btnSortAtoZ;
Button btnSortTopRated;
Button btnNearU;
ListView listView1;

ArrayList<Integer> images = new ArrayList<Integer>();
ArrayList<String>strArray=new ArrayList<String>();

ArrayList<Object> ObjectArray = new ArrayList<Object>();    

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_view_items);

    listView1=(ListView)findViewById(R.id.listView1);
    textViewHotClubs=(TextView)findViewById(R.id.textViewHotClubs);
    btnNearU=(Button)findViewById(R.id.btnNearU);
    btnSortAtoZ=(Button)findViewById(R.id.btnSortAtoZ);
    btnSortTopRated=(Button)findViewById(R.id.btnSortTopRated);

    listView1.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            String getText=strArray.get(arg2);
            if(getText=="Code")
            {
                Intent i=new Intent(ListViewItems.this, CodeClub.class);
                i.putExtra("pushText","Code");
                startActivity(i);
            }
            else if (getText=="Club Duo")
            {
                Intent i = new Intent(ListViewItems.this,ClubDuo.class);
                i.putExtra("pushText", "Club Duo");
                startActivity(i);
            }

        }
    });

    strArray.clear();
     images.clear();

     strArray.add("Code");
     strArray.add("Club Duo");


     images.add((int)R.drawable.dragon30x33);
     images.add((int)R.drawable.rainbow30x20);




}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.list_view_items, menu);
    return true;
}

}

【问题讨论】:

标签: java android sqlite listview android-listview


【解决方案1】:

您需要使用 CursorAdapter

创建一个游标来保存数据库中的数据。

创建 CursorAdapter,它接受 Cursor 对象并在 UI 中填充数据。

【讨论】:

    猜你喜欢
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-24
    • 1970-01-01
    相关资源
    最近更新 更多