如何查找edittext
附近TextView
( 「輸入linedata數量」)? 這是我code..Is有可能做這裏面LinearLayout
public class Ybus_Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ybus);
final LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
final LinearLayout main = (LinearLayout)findViewById(R.id.android_main_layout);
TextView getData=new TextView(this);
getData.setText("Enter the number of LineData : ");
getData.setId(5);
getData.setLayoutParams(params);
main.addView(getData);
final EditText edText = new EditText(this);
edText.setId(3);
edText.setLayoutParams(params);
edText .setWidth(100);
edText .setImeOptions(EditorInfo.IME_ACTION_NEXT);
edText .setInputType(InputType.TYPE_CLASS_NUMBER);
edText .setKeyListener(DigitsKeyListener.getInstance());
edText .setMaxLines(1);
main.addView(edText);
Button bt = new Button(this);
bt.setText("Click to enter Linedata");
bt.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
main.addView(bt);
final TextView text = new TextView(this);
bt.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String ed=edText.getText().toString();
int i = 0;
try{
i =Integer.parseInt(ed);
//setting value here
text.setText(i+"");
//or you can do like this
//text.setText(String.valueOf(i));
}catch(NumberFormatException ex){
text.setText("Value at TextView is not a valid integer");
}
}
});
main.addView(text);
}
}
@Raghunandan如何兄弟??我是新來的Android .. – gkn06
對不起,我誤解了這個問題。你想以編程方式移動textview旁邊的視圖? – Raghunandan
如何將edittext移動到文本視圖 – gkn06