Я пытаюсь выяснить, почему View.INVISIBLE и View.GONE в моем приложении для Android не работают.Android setVisibility View.INVISIBLE и View.GONE не работают
Я считаю, что моя логика правильно учитывает! = Нулевые значения, но, возможно, это не так?
Ниже приведен синтаксис. Моя цель в том, что если их информация, я хочу отобразить эту информацию для пользователя. Если facebook, twitter, yelp и т. Д. Не отображают информацию, я не хочу, чтобы мое белое пространство было представлено моему пользователю (это не радует глаз). Мой вопрос: что я делаю неправильно, как я могу это исправить? Мой синтаксис ниже. Благодаря
public View getView(int position, View convertView, ViewGroup parent) {
allTheshipInfo infoHolder;
if(convertView == null){
convertView = inflater.inflate(R.layout.show_dealership_information, parent, false);
infoHolder = new allTheshipInfo();
infoHolder.facebook = (TextView) convertView.findViewById(R.id.theFacebook);
infoHolder.twitter = (TextView) convertView.findViewById(R.id.theTwitter);
infoHolder.youtube = (TextView) convertView.findViewById(R.id.theYoutube);
infoHolder.googlePlus = (TextView) convertView.findViewById(R.id.theGoogle_plus);
infoHolder.yelp = (TextView) convertView.findViewById(R.id.theYelp);
convertView.setTag(infoHolder);
} else {
infoHolder = (allTheDealershipInfo) convertView.getTag();
}
try {
JSONObject jsonObject = this.dataArray.getJSONObject(position);
infoHolder.dealerships.setText(jsonObject.getString("business"));
infoHolder.state.setText(jsonObject.getString("state"));
infoHolder.city.setText(jsonObject.getString("city"));
infoHolder.phone.setText(jsonObject.getString("phone"));
infoHolder.address.setText(jsonObject.getString("address"));
infoHolder.zip.setText(jsonObject.getString("zip"));
infoHolder.email.setText(jsonObject.getString("email"));
infoHolder.website.setText(jsonObject.getString("website"));
infoHolder.facebook.setText(jsonObject.getString("facebook"));
infoHolder.twitter.setText(jsonObject.getString("twitter"));
infoHolder.youtube.setText(jsonObject.getString("youtube"));
infoHolder.googlePlus.setText(jsonObject.getString("google_plus"));
infoHolder.yelp.setText(jsonObject.getString("yelp"));
if(facebook.isEmpty()){
infoHolder.facebook.setVisibility(View.GONE);
Toast.makeText(activity, "Facebook Gone", Toast.LENGTH_SHORT).show();
} else {
infoHolder.facebook.setText(facebook);
infoHolder.facebook.setVisibility(View.VISIBLE);
Toast.makeText(activity, "Facebook Here", Toast.LENGTH_SHORT).show();
}
if(twitter.isEmpty()){
infoHolder.twitter.setVisibility(View.GONE);
Toast.makeText(activity, "Twitter Gone", Toast.LENGTH_SHORT).show();
} else {
infoHolder.twitter.setText(twitter);
infoHolder.twitter.setVisibility(View.VISIBLE);
Toast.makeText(activity, "Twitter Here", Toast.LENGTH_SHORT).show();
}
if(youtube.isEmpty()){
infoHolder.youtube.setVisibility(View.GONE);
Toast.makeText(activity, "YouTube Gone", Toast.LENGTH_SHORT).show();
} else {
infoHolder.youtube.setText(youtube);
infoHolder.youtube.setVisibility(View.VISIBLE);
Toast.makeText(activity, "YouTube Here", Toast.LENGTH_SHORT).show();
}
if(googlePlus.isEmpty()){
infoHolder.googlePlus.setVisibility(View.GONE);
Toast.makeText(activity, "GooglePlus Gone", Toast.LENGTH_SHORT).show();
} else {
infoHolder.googlePlus.setText(googlePlus);
infoHolder.googlePlus.setVisibility(View.VISIBLE);
Toast.makeText(activity, "GooglePlus Here", Toast.LENGTH_SHORT).show();
}
if(yelp.isEmpty()){
infoHolder.yelp.setVisibility(View.GONE);
Toast.makeText(activity, "Yelp Gone", Toast.LENGTH_SHORT).show();
} else {
infoHolder.yelp.setText(yelp);
infoHolder.yelp.setVisibility(View.VISIBLE);
Toast.makeText(activity, "GooglePlus Here", Toast.LENGTH_SHORT).show();
}
Toast.makeText(activity, "Call " + jsonObject.getString("business"), Toast.LENGTH_SHORT).show();
Toast.makeText(activity, "# " + jsonObject.getString("phone"), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
return convertView;
}
Мой XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="40dp"
android:orientation="horizontal">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text="@string/facebook"
android:autoLink="web"
android:id="@+id/theFacebook"
android:layout_column="0"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text="@string/twitter"
android:autoLink="web"
android:id="@+id/theTwitter"
android:layout_column="0"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text="@string/google_plus"
android:autoLink="web"
android:id="@+id/theGoogle_plus"
android:layout_column="0"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text="@string/yelp"
android:autoLink="web"
android:id="@+id/theYelp"
android:layout_column="0"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text="@string/youtube"
android:autoLink="web"
android:id="@+id/theYoutube"
android:layout_column="0"
android:layout_weight="1" />
</TableRow>
</TableLayout>
ваш метод setVisibility должен быть снаружи, если (convertView == NULL) тело. –
@ moh.sukhni Я изменил несколько вещей вокруг. Это не работает. Что я делаю не так? – valhalla
вы вносите много вещей в предложение 'else'. он должен содержать только 'infoHolder = (allTheDealershipInfo) convertView.getTag();' – njzk2