-2
嗨 我想在onActivityResult(),我得到了結果從以前的活動設置數據中的EditText,但我不能設置值到我目前的EditText .. 嗨,我的代碼:Android:EditText.setText()無法正常工作?
public class MyStuff extends Activity {
EditText messageArea;
int baseValue=200;
TextView txtCounter;
Button btnStuffOk;
Button btnStuffCancel;
ImageButton imgBrowse;
private Gallery gallery;
Bitmap myBitmap;
boolean flag=false;
int val=0;
private ArrayList<String> arrayLst=new ArrayList<String>();
protected static final int SELECT_IMAGE = 1;
protected static final int SELECT_URL = 2;
BitmapFactory.Options options = new BitmapFactory.Options();
String url_data="";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mystuff);
imgBrowse.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(
new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI),
SELECT_IMAGE);
}
});
gallery = (Gallery) findViewById(R.id.examplegallery);
gallery.setAdapter(new AddImgAdp(this));
messageArea=(EditText)findViewById(R.id.editArea01);
txtCounter=(TextView)findViewById(R.id.txtCounts);
btnStuffOk=(Button)findViewById(R.id.btnStufftOk);
btnStuffCancel=(Button)findViewById(R.id.btnStuffCancel);
messageArea.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
if(s.toString().length()<1 ||s.toString().length()>200)
{
btnStuffOk.setEnabled(false);
}
else
{
btnStuffOk.setEnabled(true);
}
txtCounter.setText(""+(baseValue-s.toString().length()));
}
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SELECT_IMAGE:
if (resultCode == Activity.RESULT_OK) {
//
break;
}
case SELECT_URL:
if (resultCode == Activity.RESULT_OK) {
messageArea.setText(data.getStringExtra("url"));
messageArea.setText("this is a test");
break;
}
}
}
}
data.getStringExtra("url")
顯示值..,但我不能給它分配INT EDITTEXT ... 請幫我...
請添加一些代碼片段,你得到了arror和logcat o/p其中顯示錯誤 – 2011-01-31 05:50:45