나는 과 TextView
을 포함하는 LinearLayout
입니다. 내 ConsoleWindow
이 루프에서 실행 중이며 각 반복에서 TextView
을 업데이트하고 싶습니다.문제 Android LinearLayout 사용
문제는 내가 EditText
을 한 번만 (그렇지 않으면 액세스 할 수 없음) 초기화하고 LinearLayout
을 한 번만 초기화 할 수 있습니다 (그렇지 않으면 EditText
이 제거됨).
LinearLayout
과
EditText
을 넣을 수 없습니다
: layout.addView(tv);
에서 IDE의 반환하기 때문에
if (firstRun) {
// initialize LinearLayout and EditText
firstRun = false;
}
// TEXTVIEW
TextView tv = new TextView(getApplicationContext())
tv.setText(dataStringTot);
layout.addView(tv); // "Qualifier must be an Expression."
". 한정자가 표현되어야합니다"
내 코드 :
public boolean firstRun = true;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getInetContent();
}
getInetContent() { // would be a thread
// getting data...
Bundle b = new Bundle();
b.putString("StringNMEA", NMEA);
Message m = mhandler.obtainMessage();
m.setData(b);
mhandler.sendMessage(m);
}
Handler handler = new Handler() {
public void handleMessage(Message msg) {
String dataString = "";
Bundle bundle = msg.getData();
if (bundle.containsKey("display")) {
ConsoleWindow(dataString);
}
}
}
private void ConsoleWindow(String dataString) {
if (firstRun) {
// initialize LinearLayout and EditText:
// LINEAR LAYOUT
LinearLayout layout = new LinearLayout(this);
setContentView(layout);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setBackgroundColor(Color.parseColor("#000000")); // black
// EDITTEXT
EditText et = new EditText(getApplicationContext());
et.setHint("Enter Command");
layout.addView(et);
firstRun = false;
}
// TEXTVIEW
TextView tv = new TextView(getApplicationContext());
tv.setText(dataStringTot);
layout.addView(tv);
}
}
가 어떻게이 문제를 해결할 수있는 다음과 같은 경우-문을
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getInetContent();
}
getInetContent() { // would be a thread
// getting data...
Bundle b = new Bundle();
b.putString("StringNMEA", NMEA);
Message m = mhandler.obtainMessage();
m.setData(b);
mhandler.sendMessage(m);
}
Handler handler = new Handler() {
public void handleMessage(Message msg) {
String dataString = "";
Bundle bundle = msg.getData();
if (bundle.containsKey("display")) {
ConsoleWindow(dataString);
}
}
}
private void ConsoleWindow(String dataString) {
// LINEAR LAYOUT
LinearLayout layout = new LinearLayout(this);
setContentView(layout);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setBackgroundColor(Color.parseColor("#000000")); // black
// EDITTEXT
EditText et = new EditText(getApplicationContext());
et.setHint("Enter Command");
layout.addView(et);
// TEXTVIEW
TextView tv = new TextView(getApplicationContext());
tv.setText(dataStringTot);
layout.addView(tv);
}
}
내 코드?
전체 메서드 게시 – Blackbelt
각 반복에서 setContentView (layout)을 호출 할 수 없습니다. – kelvincer
그 이유는 if-Statement를 원했기 때문입니다 (첫 번째 실행에서 contentview 만 설정하기 때문에). 하지만 문제는 "한정어는 표현식이어야합니다"... – blackst0ne