次のように TextView フィールドからテキストを取得しようとしています:
<TextView
android:id="@+id/text_random_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text=""
android:textColor="#FF8800"
android:textSize="30dp"
tools:context=".ImHungry" />
私が使用しているコマンドは次のとおりです。
final Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String search = R.id.text_random_text.getText().toString();
Uri uri = Uri.parse("http://www.google.com/#q=" + search);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
次のようなエラーが発生しているようです: プリミティブ型 int で getText() を呼び出すことはできません
私はこれに慣れていないので、助けていただければ幸いです。ありがとう!