当我在标题中写道时,我需要一些帮助来获取字符串数组中的项目并在文本视图中逐一显示我有代码将它们全部放在列表视图中但我需要在文本视图中逐个显示它们我的代码,抱歉我的英语不好,谢谢你的帮助......
public class MainActivity extends ListActivity {
String[] mTestArray;
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an ArrayAdapter that will contain all list items
ArrayAdapter<String> adapter;
mTestArray = getResources().getStringArray(R.array.planets_array);
/* Assign the name array to that adapter and
also choose a simple layout for the list items */
adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
mTestArray);
// Assign the adapter to this ListActivity
setListAdapter(adapter);
}
}
Run Code Online (Sandbox Code Playgroud)
XML文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" …Run Code Online (Sandbox Code Playgroud) 我有调用操作的代码,我需要最好的方式来声明运行时权限我尝试了很多代码,但我总是得到错误
这是我的基本代码任何建议,使其与运行时权限一起工作,提前感谢
public class MainActivity extends Activity {
private Button button;
private EditText etPhoneno;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonCall);
etPhoneno = (EditText) findViewById(R.id.editText1);
// add button listener
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String phnum = etPhoneno.getText().toString();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phnum));
startActivity(callIntent);
}
});
}
Run Code Online (Sandbox Code Playgroud)
}
我有这个代码从edittext获取SharedPreferences的值,然后将其发送到其他活动,不知何故我不能从其他活动使用它我想念我的代码任何建议,提前谢谢
- 我的第一个活动,从edittext获取SharedPreferences,我想从它发送值到第二个活动
public class NationalId extends Activity {
public static final String MyPREFERENCES = "MyPrefs" ;
public static final String Name = "nameKey";
SharedPreferences sharedpreferences;
final Context context = this;
private Button button;
private TextView result;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_national_id);
// components from main.xml
button = (Button) findViewById(R.id.button1);
result = (TextView) findViewById(R.id.tv1);
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
// add button listener
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// get prompts.xml view
LayoutInflater li = …Run Code Online (Sandbox Code Playgroud)