单击按钮时,片段的edittext不会刷新

时间:2013-11-18 16:51:46

标签: java android button android-fragments

我已设法访问数据库和其他片段的radiobuttons或buttonclick但是当我尝试setText的EditText时,当前片段不会刷新。我已经尝试了invalidate,postInvalidate和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;
}       
}

0 个答案:

没有答案