有人可以告诉我如何使用getExtra()和putExtra()意图吗?实际上我有一个字符串变量,比如str,它存储一些字符串数据.现在,我想将这些数据从一个活动发送到另一个活动.
Intent i = new Intent(FirstScreen.this, SecondScreen.class);
String keyIdentifer = null;
i.putExtra(strName, keyIdentifer );
Run Code Online (Sandbox Code Playgroud)
然后在SecondScreen.java中
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
TextView userName = (TextView)findViewById(R.id.userName);
Bundle bundle = getIntent().getExtras();
if(bundle.getString("strName")!= null)
{
//TODO here get the string stored in the string variable and do
// setText() on userName
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这是一个非常基本的问题但不幸的是我被困在这里.请帮忙.
谢谢,
编辑:这里我试图从一个屏幕传递到另一个屏幕的字符串是动态的.那就是我有一个editText,我得到的字符串无论用户类型如何.然后借助于myEditText.getText().toString().我将输入的值作为字符串,然后我必须传递此数据.
我想知道RTC,RTC_WAKEUP,ELAPSED_REALTIME,ELAPSED_REALTIME_WAKEUP之间的区别.
我想编写一个警报应用程序,我将设置警报并关闭我的应用程序,并期望在设置的时间内发出警报.
会有多个警报.现在我正在为模拟器编写,但稍后将在设备上进行测试.在模拟器中,一旦我设置了警报并关闭模拟器并重新启动它,那么它将被清除,正如我在RTC,RTC_WAKEUP和ELAPSED_REALTIME中找到的那样.我很迷惑.我应该使用ELAPSED_REALTIME_WAKEUP吗?我还没有看到任何使用ELAPSED_REALTIME_WAKEUP的教程.请解释.谢谢.
我的应用程序中有一个sqlite数据库.我想用它做一个可扩展的列表视图.
我已经采取了我应采取的方法.
尝试了很多相同的教程,却找不到一个教程,其中一个用本地数据库填充Expandable列表.
在android站点中有一个教程,他们用手机中的联系人详细信息填充可扩展列表.他们是从内容提供商 ExpandableList2.java这样做的
所以我的问题是我是否应该为我自己的应用程序内的数据库创建一个内容提供程序?
这是唯一的方法还是还有其他更好的方法吗?
sqlite android expandablelistview android-contentprovider simplecursoradapter
我们如何以编程方式知道我正在进行的通话是在另一方收到的?我知道有一些手机状态,如IDLE,OFFHOOK和RINGING.我希望收到通知,我正在拨打的电话已被接收,另一方断开连接或另一方无人看管.
请建议.
我在数据库中有两个表:
现在,当删除或添加第一列的房间号时,我的第二个表也应该更新.我认为这可以用TRIGGER命令,但我不确定如何使用它.
通常我的create database语句是这样的:
private static final String DATABASE_CREATE_PATIENT_ID_TABLE =
"create table " + DATABASE_PATIENT_TABLE +
" (_id integer primary key autoincrement,"
+ "patient_number text not null, room_numbertext not null, " +
"patient_initial text not null);";
Run Code Online (Sandbox Code Playgroud)
现在当房间被删除或添加到第一个表中时,我的第二个表应该更新.
private static final String DATABASE_CREATE_NOTES_ID_TABLE =
"create table " + DATABASE_NOTES_TABLE +
" (_id integer primary key autoincrement," +
" room_number text not null, time_hour text not null, " +
"notes_hour text not null, today_date text not null);";
Run Code Online (Sandbox Code Playgroud)
最初我做的是比较两个表的内容.但是,当数据增加时,这肯定会导致性能问题.所以我偶然发现了TRIGGER的事情.我认为这可以解决我的问题,但我不知道我应该如何使用它.
我想为一个对象生成一个.vcf文件,其中包含姓名,图像,电话号码,传真号码,电子邮件ID,地址等联系信息.此对象未添加到手机的通讯录中,但存储在我的应用.
一旦我的.vcf文件生成,我就可以像这样发送这个vcard
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("**generated.vcf**"), "text/x-vcard");
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
但是我没有得到如何生成这个生成的.vcf文件?
如何在运行时在相对布局中添加视图,以使其在父级的顶部对齐.假设我在单击按钮时添加了EditText.现在,这个EditText应该以EditText位于Button之上.
这是我正在做的一个例子.
button = new Button(this); //here I am just checking if the button can come above the EditText
button.setText("I am a button");
params.addRule(RelativeLayout.BELOW, editText.getId());
params.addRule(RelativeLayout.ALIGN_PARENT_ABOVE);
relativeLayout.addView(button);
Run Code Online (Sandbox Code Playgroud)
我根本无法进行对齐.任何线索都非常感谢.提前致谢.
我试图在我的活动中动态添加表行.表行处于相对布局中.它看起来很好,但不知道我哪里出错了.以下是我的代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout RLayout = (RelativeLayout)findViewById(R.id.RelativeLayout);
TableRow tableRow = (TableRow)findViewById(R.id.TableRow);
for(int i = 1; i <3; i++)
RLayout.addView(tableRow); //My code is crashing here
}
Run Code Online (Sandbox Code Playgroud)
而main.xml如下
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/RelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TableRow
android:id="@+id/TableRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
<TextView
android:id="@+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
>
</TextView>
</TableRow>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
请帮忙.
我有一个线性布局(水平),里面有3个线性布局,每个布局都有一个文本视图.
现在我想平等地划分这些线性布局.所以我给他们增加了重量1.它很完美.
但是现在当它们内部的文字宽度变化时,它们的重量不再相等:(
比如任何线性布局我删除了文本,或写了一个较小的文本或不同长度的文本然后它失去了相等的分布.如何使布局均匀分布.
还有一件事我想知道文本宽度增加了这些布局的最大分配宽度(这些将动态地给出可能是通过做宽度= 1),然后我如何将文本移动到下一行.