如何将按钮添加在java中建造一个消息旁边 [英] how to add a button next to a message in java builder

查看:111
本文介绍了如何将按钮添加在java中建造一个消息旁边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还挺新Java编程,我想创建为Android原生应用。
我的问题是,当我从我的SQLite数据库中选择一些东西 - 我想用的EventListener添加旁边的输出按钮。

Kinda new to Java programming, And I am trying to create a native app for android. my problem is, that when I select some stuff from my SQLite DB - I want to add a button with an eventlistener next to the output.

    if(view==btnViewAll)
     {
        Cursor c=db.rawQuery("SELECT * FROM catalogue", null);
        if(c.getCount()==0)
        {
            showMessage("Error", "No records found");
            return;
        }
        StringBuffer buffer=new StringBuffer();
        while(c.moveToNext())
        {
            buffer.append("Product name: "+c.getString(1)+"\n");
            buffer.append("Description: "+c.getString(2)+"\n");
            buffer.append("Price: "+c.getString(3)+"\n");
            buffer.append("Image: "+c.getString(4)+"\n\n");

        }
        showMessage("All Products", buffer.toString());
     }//end of btnViewAll

然后我ShowMessage是这样的 -

and then my ShowMessage is this -

public void showMessage(String title, String message) {
    Builder builder = new Builder(this);
    builder.setCancelable(true);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.show();
}//end of Message!

这都是我的手机上弹出,用在我的数据库记录的列表 - 但我想不通,怎么在里面添加一个按钮,每行

This all pops up on my phone, with a list of the records in my DB - but I can't figure out, how to add a button for each row in there.

帮助是AP preciated!

help is appreciated!

推荐答案

关于你最近的评论,你所需要的显示整个字符串,而不是是创建一个自定义列表,并通过您的数据库填充它。
下面是所需的步骤:

Refering to your recent comment, what you need instead of displaying the full String is to create a custom list and populate it via your DB. Here are the steps required :

1)创建一个对象的用户,用姓名/电话号码

1) Create an Object User, with name/phone number

2)当解析您的数据库,返回一个列表

2) When parsing your DB, return a list

3)创建扩展ArrayAdapter一个CustomAdapter

3) Create a CustomAdapter extending ArrayAdapter

4)修改XML,以便有只有一个ListView

4) Change your xml so that there's only a listView

5)在您的活动,调用的AsyncTask获取您的数据库(如你可能已经这样做),然后使用列表通过适配器来填充的ListView。

5) In your activity, call an AsyncTask to fetch your DB (as you probably already do), then use the List to populate the ListView through the Adapter.

另外提示:创建布局 row.xml 这会在你的适配器,在那里你必须显示你的用户信息所需要的小工具被夸大(即姓名/电话N°)+按钮。而在适配器的getView,膨胀你的 row.xml ,与数据更新的值,并设置行为鼠标。

Further tips : create a layout row.xml that'll be inflated in your Adapter, where you'll have the Widgets needed to display informations about your user (ie name/phone n°) + a button. And in the getView of the adapter, inflate your row.xml, update the values with the data, and set the behaviour for the button there.

下面是一个伟大的教程中,你会发现一切细节: HTTP:// WWW .vogella.com /教程/ AndroidListView / article.html

Here's a great tutorial where you'll find everything in details : http://www.vogella.com/tutorials/AndroidListView/article.html

祝你好运吧!

这篇关于如何将按钮添加在java中建造一个消息旁边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆