在我的 Android 应用程序中,我将片段活动用于片段标签主机。在该片段活动中,我使用了一个编辑文本框,我无法在该编辑文本中编辑或输入文本。
该片段活动的代码是
package com.example.fragmenttabhost;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
public class FragmentTab extends android.support.v4.app.Fragment {
private Button btnTest;
private Activity context;
private EditText edtTest;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context=getActivity();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_layout, container, false);
return v;
}
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
context=getActivity();
btnTest=(Button)context.findViewById(R.id.button1);
edtTest=(EditText)context.findViewById(R.id.editText1);
edtTest.setText("Test text");
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Test");
btnTest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String str=edtTest.getText().toString();
builder.setMessage(str);
builder.show();
}
});
}
}