在我的应用程序中,我动态生成两个线性布局并将它们添加到 ScrollView。
每个 LinearLayout 都有一个 Button 和一个 Edit Text,我希望当单击第二个 LinearLayout 的 Button 时,第一个 LinearLayout 会被禁用。
代码:
package com.integrated.mpr;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class Page1 extends Activity implements OnClickListener{
int i;
int[][] id = new int[pos][3];
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
int p =0;
Log.d("value of ", ""+pos);
for(int i =0;i<2;i++){
for(int j =0;j<3;j++){
id[i][j] = p;
p++;
}
}
//In each row 1st column is the id for button
//2nd column id for edittext
//3rd column id for Linearlayout
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
for(i=0;i<2;i++){
LinearLayout llay = new LinearLayout(this);
llay.setOrientation(LinearLayout.VERTICAL);
llay.setId(id[i][2]);
EditText et = new EditText(this);
et.setId(id[i][1]);
Button stop = new Button(this);
stop.setText("Submit");
stop.setId(id[i][0]);
stop.setOnClickListener(this);
llay.addView(et);
llay.addView(stop);
ll.addView(llay);
}
sv.addView(ll);
this.setContentView(sv);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId()==id[1][0]){
//when te second Button is clicked
// now here disable the 1st linear layout
//Can't think how to do it
}
}
}