我是 Android 编程新手,我很确定这就是我需要的。我有一个在开始时加载的页面,其中有一个微调器、一些编辑文本框和两个按钮。一键清除盒子并重置旋转器。另一个按钮应该加载一个新的活动(我猜),我需要加载 EditTexts 和微调器中的内容。
现在我让它烤面包,这样我就可以测试所有东西是否都被正确抓取。这是我现在的活动:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class directoryApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchscreen);
//Declaring these so I can use them when the button is clicked.
final Spinner depts = (Spinner) findViewById(R.id.dept);
final ArrayAdapter<CharSequence> deptsAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item);
deptsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
final EditText fname = (EditText) findViewById(R.id.fname);
final EditText lname = (EditText) findViewById(R.id.lname);
final EditText aim = (EditText) findViewById(R.id.aim);
final EditText phone = (EditText) findViewById(R.id.phone);
depts.setAdapter(deptsAdapter);
for(int i = 0 ; i < fillSpinner().length ; i++){
deptsAdapter.add(fillSpinner()[i]);
}
//Search Button on click, makes a "toast" message with grabbed web string and whatever was entered into the fields.
findViewById(R.id.search).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Here is where the search button does it's thing.
Toast.makeText(BNYDirectory.this, fname.getText() + " " + lname.getText() + " " + aim.getText() + " " + phone.getText() + " " + depts.getSelectedItem() + " " + deptIDs()[(int)depts.getSelectedItemId()], Toast.LENGTH_SHORT).show();
}
});
}
}
我需要传递 fname.getText()、lname.getText()、aim.getText()、phone.getText() 和 deptIDs()[(in)depths.getSelectedItem Id()] (所有这些我都得到作为字符串)。
转到下一页的最佳方式是什么(我将使用这些来获取结果并显示)?也有可能,在单击搜索时,我可以让它从网络上获取结果并将其放入字符串数组中,然后只传递它,但我不想这样做。
我可以使用任何例子吗?
您创建一个 Intent,指定第二个活动的类名称。然后,您可以向意图添加额外的数据,每条数据都与一个唯一的字符串关联,该字符串充当查找数据的键。然后,新活动可以使用相同的键检索数据。参见 参考资料 部分打开新屏幕 http://developer.android.com/resources/faq/commontasks.html#opennewscreen在资源文档的“常见任务”部分中获取示例代码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)