アプリケーション内で一定のApp:私は適用必要、私はクラスの数を最小限にするためにアプリケーションの定数とアンドロイドのアプリケーションに</p> <p>例ListViewコントロールとメニューオプションを作成し
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context=this;
lv=(ListView) findViewById(R.id.listView);
lv.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item,prgmNameList));
lv.setOnItemClickListener(this);
}
OnClickListener
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position)
{
case 0:
Intent intent = new Intent(this, First.class);
intent.putExtra(AppConstants.MAIN_ACTIVITY_TAG,lv.getItemAtPosition(position).toString());
startActivity(intent);
break;
}
しかしをアプリ定数をメニューオプションにも割り当てます しかし、私はそれを行う方法を知らない:
ここでは10は、メニューオプションのためのコード
// create action options for options
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.news, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_about) {
Intent intent = new Intent(this,Extras.class);
startActivity(intent);
}
if (id == R.id.action_advertise) {
return true;
}
if (id == R.id.action_contact) {
return true;
}
if (id == R.id.action_help) {
return true;
}
return super.onOptionsItemSelected(item);
}
私がリストビューとしてではなく、メニューオプションのために同じことをやりたいです。
この問題を解決するのを手伝ってください。
使用string.xmlをします。 – ADM
詳細を教えてください、私は混乱しています –
正確に何の問題がありますか? xmlで文字列定数を使用しますか? – ADM