找到解决方案:textview
在oncreateOptionMenu
代替Oncreate
方法中声明。
Multiple marker
问题:当我为相应的 id 定义文本视图时,它会产生错误。
TwitterSearchActivity.java
package com.example.twittersearchactivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class TwitterSearchActivity extends Activity {
TextView tweet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_twitter_search);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.twitter_search, menu);
return true;
}
tweet=(TextView)findViewById(R.id.tweet_txt);
}
activity_twitter_search.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TwitterSearchActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
/>
<TextView
android:id="@+id/intro_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textStyle="italic"
android:text="@string/intro"
/>
<EditText
android:id="@+id/search_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/hint"
android:layout_below="@+id/intro_txt"
android:padding="10dp"
android:background="#ffff66"
android:layout_margin="5dp"
/>
<Button
android:id="@+id/search_btn"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/search_label"
android:layout_below="@+id/search_edit"
android:onClick="searchTwitter"
android:layout_margin="5dp"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/search_btn">
<TextView
android:id="@+id/tweet_txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:padding="10dp"
android:background="#330000"
android:textColor="#ffffff"
android:layout_margin="5dp"
android:text="@string/placeholder"
android:freezesText="true"
/>
</ScrollView>
</RelativeLayout>
错误
Multiple markers at this line
- Syntax error on token ".", ... expected
- Syntax error, insert ";" to complete FieldDeclaration
- Syntax error on token "tweet", VariableDeclaratorId expected after this token
- Return type for the method is missing
- Syntax error, insert "}" to complete ClassBody