gpt4 book ai didi

android - 在 Android App UI 中实现 "Drilldown"导航

转载 作者:IT老高 更新时间:2023-10-28 23:20:57 26 4
gpt4 key购买 nike

我正在尝试学习如何在 Android 中进行操作,但我不确定构建界面的最佳方式。

我一直致力于移植一个 iPhone 应用程序,该应用程序使用导航 Controller 和表格 View 来查看不同的部分:基本上,有人触摸表格中的一个单元格,它会向下钻取到另一个表格。当他们触摸该表格上的单元格时,它会向下钻取到显示信息的 web View 。

我想为 android 应用程序做类似的事情,但我不知道如何,或者是否有更好的原生于 Android 的方法。我已经弄清楚如何将 webview 用于我的目的,但在表树中向前和向后移动还不清楚。

最佳答案

所以在 iphone 上,当您说向下钻取时,我猜您的意思是当用户在列表行上进行润色并从右侧滑动一个新 View 时,大多数情况下它的顶部都有一个导航栏让用户选择返回?

android 处理这个问题的方式很简单,就是启动一个新的 Activity 。因此,当单击 listItem 时,您将拥有您的“书籍”ListActivity,您将定义一个启动您的“章节”ListActivity 的新 Intent ,依此类推。 iphone 顶部的导航栏不是 android 中的标准 UI,因为大多数人将专用的“返回”键视为返回预览屏幕的一种方式。

如果您以前没有见过 Intent ,这就是您启动 Intent 的方式:

Intent chaptersIntent = new Intent(this, Chapters.class);
this.startActivity(chaptersIntent);

这篇文章值得快速阅读,因为它完美地解释了 Activity

http://d.android.com/guide/topics/fundamentals.html

另外看看安卓版的TableView - ListView:

http://d.android.com/reference/android/widget/ListView.html

和 ListActivity:

http://d.android.com/reference/android/app/ListActivity.html


编辑::示例代码我会这样做

public class Books extends ListActivity {

private String[] mBooks = new String[]{ "Book1", "Book2", "Book3", "Book4" };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ArrayAdapter<String> booksAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
android.R.id.text1,
mBooks);

this.setListAdapter(booksAdapter);

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);

Intent mViewChaptersIntent = new Intent(this, Chapters.class);
mViewChaptersIntent.putExtra("BookName", mBooks[position]);
startActivity(mViewChaptersIntent);
}

}

因此,您将书的 id 作为 Intent 的额外内容传递,然后在您的章节 Activity 中,您会在 onCreate 方法中获得该额外内容:

    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Bundle extras = getIntent().getExtras();
if(extras != null) {
String bookId = extras.getString("BookName");
}
}

最后确保所有新 Activity 都添加到您的 AndroidManifest.xml 文件中:

<activity android:name=".YourClassName"
android:label="@string/activity_name"
>
</activity>

希望有帮助

关于android - 在 Android App UI 中实现 "Drilldown"导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2958560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com