我正在尝试学习如何在 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/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我怎样才能完成http://php.net/manual/en/function.call-user-func-array.php在ruby中?所以我可以这样做:classAppdeffoo(a,b)putsa+benddefbarargs=[1,2]App.send(:foo,args)#doesn'tworkApp.send(:foo,args[0],args[1])#doeswork,butdoesnotscaleendend 最佳答案 尝试分解数组App.send(:foo,*args)
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我需要在RubyonRails中实现无向图G=(V,E)并考虑构建一个Vertex和一个Edge模型,其中Vertex有_多条边。由于边恰好连接两个顶点,您将如何在Rails中执行此操作?您是否知道任何有助于实现此类图表的gem或库(对重新发明轮子不感兴趣;-))? 最佳答案 不知道有任何现有库在ActiveRecord之上提供图形逻辑。您可能必须实现自己的Vertex、EdgeActiveRecord支持的模型(请参阅Rails安装的rails/activerecord中的vertex.rb和edge.rb/test/fixtur
我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas