如何创建类似 Android CallLog 布局的布局

发布于 2024-10-11 13:51:46 字数 2023 浏览 2 评论 0原文

嘿,我想为我的应用程序创建一个这样的布局。当然,功能也会有所不同。我正在研究这个的源代码,并且找到了执行此操作的 xml 文件。我只是不知道如何在活动中实现它,如何调用,创建什么,列表视图等。

alt text

我的意思是,我只想用更大的字体列出名称,并像图片中那样列出日期,用小字体但向右对齐。

因为,我想从我创建的数据库中获取数据并像 CallLog 列表一样打印它。

我的意思是,Android 如何使带有该图标的日期在右侧对齐,并且字体较小?

所以这是我的活动,我只是不知道要使用源代码中的哪个 xml 文件,或者要实现什么方法,以便我可以像图像示例一样打印数据。

   public class RatedCalls extends ListActivity {

private static final String LOG_TAG = "RatedCalls";
private TableLayout table;
private CallDataHelper cdh;
private TableRow row;
private TableRow row2;

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.recent_calls);

    Log.i(LOG_TAG, "calling from onCreate()");

    cdh = new CallDataHelper(this);

    startService(new Intent(this, RatedCallsService.class));
    Log.i(LOG_TAG, "Service called.");
    Log.i(LOG_TAG, "before call fillList");

    /*
     * mAdapter = new RecentCallsAdapter();
     * getListView().setOnCreateContextMenuListener(this);
     * setListAdapter(mAdapter);
     */

    fillList();
    Log.i(LOG_TAG, "after call fillList");

}

public void onResume() {

    super.onResume();
    fillList();

}

public void fillList() {

    Log.i(LOG_TAG, "entered on fillList");
    List<String> ratedCalls = new ArrayList<String>();
    ratedCalls = this.cdh.selectTopCalls();


     //setListAdapter(new ArrayAdapter<String>(this, R.layout.recent_calls_list_item,
     //ratedCalls));


    ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    getListView().setOnCreateContextMenuListener(this);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {


            Toast.makeText(getApplicationContext(),
                    ((TextView) view).getText(), Toast.LENGTH_LONG).show();
        }
    });

}

 }

谢谢。

Hey I want to create a layout like this for my application. Of course the functionalities will be differents. I'm studying the source code for this, and I found the xml files that does that. I just dont know how to implement that in the activity, how to call, what to create, a listview, etc.

alt text

I mean, I just want to list the name with a bigger font and the date like in the image, with a small font but aligned to the right.

Because, I want to get the data from the database I've created and print it like this list of CallLog.

I mean, how Android makes the date with that icon align in the right, with a small font size?

So this is my activity, I just dont know what xml file from the source code to use, or what method to implement so I can print the data like the image example.

   public class RatedCalls extends ListActivity {

private static final String LOG_TAG = "RatedCalls";
private TableLayout table;
private CallDataHelper cdh;
private TableRow row;
private TableRow row2;

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.recent_calls);

    Log.i(LOG_TAG, "calling from onCreate()");

    cdh = new CallDataHelper(this);

    startService(new Intent(this, RatedCallsService.class));
    Log.i(LOG_TAG, "Service called.");
    Log.i(LOG_TAG, "before call fillList");

    /*
     * mAdapter = new RecentCallsAdapter();
     * getListView().setOnCreateContextMenuListener(this);
     * setListAdapter(mAdapter);
     */

    fillList();
    Log.i(LOG_TAG, "after call fillList");

}

public void onResume() {

    super.onResume();
    fillList();

}

public void fillList() {

    Log.i(LOG_TAG, "entered on fillList");
    List<String> ratedCalls = new ArrayList<String>();
    ratedCalls = this.cdh.selectTopCalls();


     //setListAdapter(new ArrayAdapter<String>(this, R.layout.recent_calls_list_item,
     //ratedCalls));


    ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    getListView().setOnCreateContextMenuListener(this);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {


            Toast.makeText(getApplicationContext(),
                    ((TextView) view).getText(), Toast.LENGTH_LONG).show();
        }
    });

}

 }

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风轻花落早 2024-10-18 13:51:46

这只是一个 2 步过程:

  1. 创建一个代表列表中 1 项的布局 Xml 文件。
  2. 扩展阵列适配器并在那里使用您的自定义布局文件。互联网上有几个关于如何扩展阵列适配器的示例。

It's just a 2 step process:

  1. Create a Layout Xml file which represents 1 item of your list.
  2. Extend Array Adapter and use your custom layout file there. There are several examples on the internet on how to extend Array Adapter.
我一直都在从未离去 2024-10-18 13:51:46

我将创建一个包含多个文本视图的列表视图。

I'm going to create a listview with multiple textviews.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文