在 Android 的用户界面中显示数据
我正在尝试创建一个简单的 Android 应用程序。我是 Android 和 java 新手。我创建了一个简单的界面,用户可以通过该界面登录到应用程序。
现在我想添加一个用户界面,用户可以在其中存储一些详细信息。
例如。信用卡详细信息。
UI 应该具有多行和多列。用户在其中存储他的多个信用卡详细信息。用户界面有一个按钮(添加新卡按钮)。用户可以单击该按钮并添加新卡详细信息。 UI 应立即显示新添加的条目。 (此应用程序将有多个用户。)我所做的列表是:
- 我创建了 ccdetails 表(在 dbadapter.java 中)
- 我编写了插入查询。
我要做的是
- 编写查询来向用户显示 ccdetails。(但我自己可以做到这一点)
- 在 UI 中向用户显示这些 ccdetails(我已经在上面给出了 UI 的详细信息。)
我无法执行第二部分。我只是不知道如何为此编写java文件、xml文件。我不知道如何在 UI 中显示用户的详细信息。为此我必须在 dbadapter.java 文件中进行哪些更改。
任何人都可以向我提供一个资源,我可以在其中获得几乎类似情况的源代码或您认为合适的任何其他内容。提前致谢。 (我在win 7机器上使用eclipse。)
I am trying to create a simple android application. I am new to Android and java. I have created a simple interface by which user can log in to the application.
Now I want to add a UI in which user can store some details.
eg. Credit card details.
The UI should have multiple rows and columns. In which the user stores his multiple credit card details. The UI have a button (add new card button.) User can click on that button and add a new card details. The UI should immediately show the new added entry. (This application will have multiple users.) List of what I have done is :
- I have created ccdetails table(in dbadapter.java)
- I have written the insert query.
What I have to do is
- Write query to show users ccdetails.(but I can do this myself)
- Showing those ccdetails in a UI to the user(I have given the details of the UI above.)
I am unable to do this second part. I just don't have any idea how to write the java file, xml file for this. I dont know how to show the details of the user in UI. What changes I have to do in dbadapter.java file for this.
Can anybody please provide me a resource where I can get source code for almost similar situation or any other thing that you think appropriate. Thanks in advance. (I am using eclipse in win 7 machine.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将
ListActivity
与CursorAdapter
结合使用(此外,完成记事本示例也会有所帮助。
Use a
ListActivity
with aCursorAdapter
(example).Also, it would help to work through the notepad example.
Android 活动布局是在名为 res/layout/ 的文件夹中以 XML 形式定义的。定义所需的布局后,您可以
在 Activity 的 onCreate 函数中调用。您可以在活动中获取名为 views 的布局对象的引用,并根据需要操作它们以显示数据或您想要的任何内容,方法是使用
For your UI you would need a ListView 和 按钮。
ListViews 内的数据通过 Adapter 进行管理。
阅读一些 Hello World 教程,尤其是其他答案中提到的记事本教程。
Android activity layouts are defined in XML inside a folder called res/layout/. After you have defined the layout that you need you call
inside your activity's onCreate function. You can obtain references for your layout objects called views inside your activity and manipulate them as needed to display data or whatever you want there by using
For your UI you would need a ListView and a Button.
Data inside ListViews is managed through an Adapter.
Go through some Hello World tutorials and especially the Notepad tutorial as mentioned in other answers.
您可以使用RelativeLayout 来轻松创建此类布局。
您可以参考这个链接,它描述了不同类型的布局。
You may go for RelativeLayout for creating these kind of layouts easily.
You may refer this link which describes different type of layouts.
请参阅http://developer.android.com/resources/tutorials/hello-world。 html
onClick按钮,调用返回数据的方法,然后在相应的小部件中设置值。
Refer http://developer.android.com/resources/tutorials/hello-world.html
onClick of your button,call the method which returns data and then set the values in the corresponding widgets.