Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 片段的编辑文本不';单击按钮时无法刷新_Java_Android_Button_Android Fragments - Fatal编程技术网

Java 片段的编辑文本不';单击按钮时无法刷新

Java 片段的编辑文本不';单击按钮时无法刷新,java,android,button,android-fragments,Java,Android,Button,Android Fragments,我已经成功地访问了数据库和其他片段的单选按钮或buttonclick,但是当我尝试设置EditText的文本时,当前片段没有得到刷新。我尝试过无效、后验证和refreshDrawableState,但没有成功。有什么建议吗 public static class Tsiatisto extends Fragment { public Tsiatisto() {} @Override public View onCreateView(LayoutInflater inflater,

我已经成功地访问了数据库和其他片段的单选按钮或buttonclick,但是当我尝试设置EditText的文本时,当前片段没有得到刷新。我尝试过无效、后验证和refreshDrawableState,但没有成功。有什么建议吗

public static class Tsiatisto extends Fragment
{       
public Tsiatisto() {}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{                   
View rootView = inflater.inflate(R.layout.tsiatisto, container, false);

mViews.add(inflater.inflate(R.layout.tsiatisto, container));

DataBaseHelper myDbHelper = new DataBaseHelper(this.getActivity().getApplicationContext());         

try 
{
myDbHelper.createDataBase(); 
myDbHelper.openDataBase();
}catch(IOException ioe) 
{ 
throw new Error("Unable to create database"); 
}        

final SQLiteDatabase db = myDbHelper.getDB();       

//Cursor cursor =  db.query("Tsiatista ORDER BY RANDOM() LIMIT 1", new String[] { "*" }, null, null, null, null, null);

final View button = rootView.findViewById(R.id.buttonGo);
button.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) 
{
View fs;
RadioGroup rg;
int selectedId;
RadioButton rb;

fs = (View) mViews.get(0);
rg = (RadioGroup) fs.findViewById(R.id.radioGroupFS);
selectedId = rg.getCheckedRadioButtonId();
rb = (RadioButton) fs.findViewById(selectedId);
funnySerious = (String) rb.getText();  

fs = (View) mViews.get(1);
rg = (RadioGroup) fs.findViewById(R.id.radioGroupMF);
selectedId = rg.getCheckedRadioButtonId();
rb = (RadioButton) fs.findViewById(selectedId);
malefemale = (String) rb.getText();  

fs = (View) mViews.get(2);
rg = (RadioGroup) fs.findViewById(R.id.radioGroupDC);
selectedId = rg.getCheckedRadioButtonId();
rb = (RadioButton) fs.findViewById(selectedId);
dirtyclean = (String) rb.getText();  

Cursor cursor =  db.rawQuery("SELECT Verse FROM Tsiatista WHERE FunnySerious = '" + funnySerious + "' AND (MaleFemale = '" + malefemale + "' OR MaleFemale = 'Both')", null);

if(cursor.moveToFirst())
{                   
String verse = (String) cursor.getString(cursor.getColumnIndex("Verse"));

EditText et = (EditText) mViews.get(3).findViewById(R.id.tsiatistoTxt);
et.setText(verse);

cursor.close();

View vv = mViews.get(3);
//vv.();
//vv.postInvalidate();
//vv.refreshDrawableState();
//View ve = (View) mViews.get(3).findViewById(R.id.tsiatistoTxt);
//ve.removeAllViews();
//ve.refreshDrawableState();

}   

}
}
);

return rootView;
}       
}

我建议使用
getView()
方法调用,而不是
get(index)我不确定您是否获得了对UI元素的正确引用。示例
EditText myEditText=(EditText)getView().findViewById(R.id.myEditText)
我还建议将所有这些代码移出
onCreateView()
方法,并将其移到onActivityCreated()或onViewCreated()中。我相信onCreateView方法是用来进行最简单的UI膨胀的,在这种方法中引用元素可能会非常费力,而且不完全可靠。