layout-inflater

android dynamically add layouts under each other

落花浮王杯 提交于 2019-12-01 00:24:28
I'm trying to add multiple layouts dynamically under each other. So I wrote the following code: for (int i = 1; i <= layoutCounter; i++) { View neu = inflater.inflate(R.layout.vote, parent, false); neu.setId(layoutID); if (layoutID == 1) { params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.BELOW, R.id.txtMultiline); } else { params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.BELOW, neu

Duplicate Views on Android during Run-time

北城以北 提交于 2019-11-30 15:27:52
I have created a Layout file for an activity. In this layout I have created a LinearLayout with a textview and an edittext. Now I want to create additional LinearLayouts that will look and contain the exact same views that my original LinearLayout, but with different texts. I also want to do it programmatically during run because the amount of these LinearLayout will vary between runs. I've read some about inflaters but I don't understand them enough to use them. I'm thinking something like this, obviously the code is wrong, but hopefully you understand what I want to do: LinearLayout llMain =

Unconditional layout, inflation from view adapter: Should use View Holder pattern

点点圈 提交于 2019-11-30 12:24:01
问题 I am getting following warning in eclipse: Unconditional layout inflation from view adapter: Should use View Holder pattern (use recycled view passed into this method as the second parameter) for smoother scrolling. on: convertView = vi.inflate(R.layout.activity_friend_list_row, parent, false); I have a base adapter with a CheckBox implemented and I have added a tag to make the CheckBox work. Here is the code: public View getView(final int position, View convertView, ViewGroup parent) {

Loading timePickerDialog from a fragment

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 09:24:48
问题 I am trying to use a custom time picker and then run the picker from a fragment. This is the code for the time picker dialog (TimePickerFragment.java): package com.ravit.android.aroundtheclock; import android.app.Dialog; import android.app.DialogFragment; import android.app.Fragment; import android.app.TimePickerDialog; import android.os.Bundle; import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android

Why to use Inflater in listview

安稳与你 提交于 2019-11-30 05:14:19
I always had ambiguity on why we need to use inflater in android, Why are they used in ListView for custom layouts (like below)? What is an Inflater ? What is the advantage of using Inflater ? public class MobileArrayAdapter extends ArrayAdapter<String> { private final Context context; private final String[] values; public MobileArrayAdapter(Context context, String[] values) { super(context, R.layout.list_mobile, values); this.context = context; this.values = values; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater)

Unconditional layout, inflation from view adapter: Should use View Holder pattern

感情迁移 提交于 2019-11-30 02:40:20
I am getting following warning in eclipse: Unconditional layout inflation from view adapter: Should use View Holder pattern (use recycled view passed into this method as the second parameter) for smoother scrolling. on: convertView = vi.inflate(R.layout.activity_friend_list_row, parent, false); I have a base adapter with a CheckBox implemented and I have added a tag to make the CheckBox work. Here is the code: public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder mViewHolder; mViewHolder = new ViewHolder(); LayoutInflater vi = (LayoutInflater) activity

Loading timePickerDialog from a fragment

我只是一个虾纸丫 提交于 2019-11-29 15:27:47
I am trying to use a custom time picker and then run the picker from a fragment. This is the code for the time picker dialog (TimePickerFragment.java): package com.ravit.android.aroundtheclock; import android.app.Dialog; import android.app.DialogFragment; import android.app.Fragment; import android.app.TimePickerDialog; import android.os.Bundle; import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TimePicker; import java.util.Calendar; /** * A simple {@link Fragment} subclass. */ public class

Why to use Inflater in listview

懵懂的女人 提交于 2019-11-29 03:04:42
问题 I always had ambiguity on why we need to use inflater in android, Why are they used in ListView for custom layouts (like below)? What is an Inflater ? What is the advantage of using Inflater ? public class MobileArrayAdapter extends ArrayAdapter<String> { private final Context context; private final String[] values; public MobileArrayAdapter(Context context, String[] values) { super(context, R.layout.list_mobile, values); this.context = context; this.values = values; } @Override public View

How to prevent items from getting duplicated when scrolling recycler view

℡╲_俬逩灬. 提交于 2019-11-28 17:38:36
I have created a row inside recycler view and inside that I have inflated two rows or more but when I scroll the items are getting used again. I am not getting where to recycle view or remove them dynamically I need a feed and their comments.For comments I need to inflate layouts to display them below feeds for which getCommentInflaterView method is created. But the view created using getCommentInflaterView() gets duplicated. MyAdapterClass: public class AllFeedsAdapter extends RecyclerView.Adapter<AllFeedsAdapter.ViewHolder> { ArrayList<Data> arrayListAllFeedsData; Comment objComment; Context

“Avoid passing null as the view root” warning when inflating view for use by AlertDialog

亡梦爱人 提交于 2019-11-28 16:02:05
I get the lint warning, Avoid passing null as the view root when inflating views with null as parent , like: LayoutInflater.from(context).inflate(R.layout.dialog_edit, null); However, the view is to be used as the content of an AlertDialog , using setView on AlertDialog.Builder , so I don't know what should be passed as the parent . What do you think the parent should be in this case? Use this code to inflate the dialog view without a warning: View.inflate(context, R.layout.dialog_edit, null); The short story is that when you are inflating a view for a dialog, parent should be null, since it