在我的节目我有什么是二AutoCompleteTextView
一个Button
和TableLayout
表现出了一定的成绩。在这个程序中,TableLayout
是隐藏的,只有在生成结果后才会显示。隐藏按钮
我也希望能让Button
只在用户填写AutoCompleteTextView
后才出现,但是在我写的代码中,我写的代码没有按照我希望的方式运行。
calculate = (Button)findViewById(R.id.calculate);
if(location.getText().toString().length()<1 && destination.getText().toString().length()<1)
{
calculate.setVisibility(View.INVISIBLE);
}
else
{
calculate.setVisibility(View.VISIBLE);
calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(location.getText().toString().length()<1 || destination.getText().toString().length()<1)
{
Toast.makeText(getApplicationContext(), "Give values before placing a query", Toast.LENGTH_LONG).show();
}
else{
@SuppressWarnings("deprecation")
String url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins="+URLEncoder.encode(location.getText().toString())+"&destinations="+URLEncoder.encode(destination.getText().toString())+"&unit=metric&mode=driving&sensor=false";
new ReadDistanceJSONFeedTask().execute(url);
z=+1;
isNormal=false;
supportInvalidateOptionsMenu();
}
}
});
}
在此代码Button
根本不会出现在所有。有人可以帮忙吗?提前致谢。
这是哪里的代码片段位于何处? – 2013-04-08 14:44:15
在OnCreate() – 2013-04-08 14:45:06
你只计算你的按钮知名度一次,在开始时,当文本肯定是空的,所以按钮消失再也没有回来。听起来像你应该听取文本中的变化,并在发生时计算你的按钮可见性。 – Oren 2013-04-08 14:45:17