我正在尝试从 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);
我似乎收到一个错误,指出:Cannot invoke getText() on the original type int
我是新手,所以任何帮助将不胜感激。谢谢!