私はプロジェクト用のアプリを持っています。私の考えは、3タブアプリを作成することでした、各タブには、トピックを表すいくつかのボタンがあります。各トピックには、特定のボタンをクリックすると開いたアクティビティに表示したい情報が入ったtxtファイルがあります。同じアクティビティが開かれますが、入力されたテキストは押されたボタンによって異なります。/rawに保存されたテキストでアクティビティを入力する方法
現在、テキストを表示する機能以外はすべてがあります。現在、/ rawにはtxtとして保存されています。
私は入力リーダーとtxtとxmlを見ています(以前は簡単でした)、私はまだ苦労しています。
特定のtxtファイルを表示することができても、どのボタンが押されたかに応じて動作させる方法がわかりません。
コンテンツ保持アクティビティには、.txtファイルのテキストを入力する予定のテキストビューがあります。
ご協力いただければ幸いです。
このキャッチで構文エラーが発生しました。
public class MartialTab extends Activity {
Button btn1, btn2;
String choice;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the martial arts tab");
setContentView(textview);
setContentView(R.layout.martial_tab);//takes layout from martial_tab.xml
btn1 = (Button) findViewById(R.id.kickboxingButton);//instantiates a button called btn1 one from the xml
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
kickBoxingBut(v, choice);
}//calls the method
});//end of method
btn2 = (Button) findViewById(R.id.grecoroman);//instantiates a button called btn1 one from the xml
btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
grecoromanBut(v);
}//calls the method
});//end of method
}
// private void kickBoxingBut() {//button1 method
//new AlertDialog.Builder(this).setTitle("AlertNotification").setMessage(
// "This is an Alert Dialogue Toast").setNeutralButton("Click Me!", null).show();
//creates an alert notification with the above text
//}
public String kickBoxingBut(View view, String s) {
startActivity(new Intent(this, ContentHolder.class));
this.choice = "kick";
return choice;
}
public void grecoromanBut(View view) {
startActivity(new Intent(this, ContentHolder.class));
}
}
、
その中にボタン付きEDIT
活動を、それを理解しようと最後の15分を費やした情報を保持している活動
public class ContentHolder extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context m_Context = getApplicationContext();
TextView textview = new TextView(this);
textview.setText("This is the content view");
setContentView(textview);
Bundle extras = getIntent().getExtras();
if(extras !=null) {
String value = extras.getString("choice");
}
InputStream input;
try {
input = m_Context.getAssets().open("choice");
DataInputStream in = new DataInputStream(input);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println(strLine);
textview.setText(strLine);
}
// Close the input stream
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//setContentView(R.layout.main);
}
このsetContentView問題です。上記のように、戻り値の型を期待しているので動作しません。それをContentHolderに変更しても動作しません。
あなたが見ることができるように、私はそれはそれでは動作しないだろう、一番下にsetcontentViewをコメントアウトそこ。私は完全にatmに固執しています。 – TroothHertz
基本的には、ボタンを押したときに応じてテキスト文書を読み込もうとしていますか? –
ユーザがボタンをクリックすると、その中のテキストを含むアクティビティが開きます。それは簡単だろうと思った。また、その印刷ステートメントが気に入らない – TroothHertz