layout-inflater

Create or inflate views programmatically in a RecyclerView OnCreateViewHolder

别来无恙 提交于 2019-12-07 16:12:09
问题 Basically I wanted to create a layout or inflate a layout programatically with a RecyclerView , but was unable to do so. As I know how to do with xml by inflating it, but out of curiosity I wanted to do it programatically. My adapter code is as follows: public class ACShare extends RecyclerView.Adapter<ACShare.VHShare>{ private List<Integer> listDrawalbe; public ACShare(Context context) { TypedArray drawables = context.getResources().obtainTypedArray(R.array.s_array_contact_us_share);

Programmatically add Views inside a (Linear)Layout (that is inside a ScrollView)

江枫思渺然 提交于 2019-12-07 08:14:14
问题 I have an app that, after some clicking, shows activity with news contents. I want at a bottom of that to show comments, which are dynamically loaded in async task. One approach is to use ListView and custom ArrayAdapter, but, i would have to put ListView inside a ScrollView, and it is is a problem, even if i manually override ListView's height. It shows one list item, and one part of the following one. The other approach is to define LinearLayout as a holder for comments, than inflate

Crash after adding footer to ListView

痞子三分冷 提交于 2019-12-07 04:51:31
问题 I'm trying to add footer to ListView but application crashes after this line of code: getListView().addView(footerView); . I'm new to android and this is my first experience with ListView . If is possible I need short explanation of inflate method. Thanks! ToDoListAdapter mAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a new TodoListAdapter for this ListActivity's ListView mAdapter = new ToDoListAdapter(getApplicationContext(

Using LayoutInflater and AlertDialog

℡╲_俬逩灬. 提交于 2019-12-06 17:01:30
Im trying to get an AlertDialog to inflate from a customview. I think I know what the problem is but I dont know how to fix it. I have a (View V) on LongClick and Button1 is using "alertdialog" to find data. I'm getting a NullPointer Exception on line TextView stax1=(TextView)findViewById(R.id.xxx); The only thing that makes sense is I have the Dialog looking in "alerthelp" when it should looking in the activity it came from. How do I fix this? lay1.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { LayoutInflater myLayout = LayoutInflater.from(context);

Add imageview dynamically to existing view

只谈情不闲聊 提交于 2019-12-06 12:48:05
问题 I'm developing an app which on start up will show a pre-defined layout like Image(1) in below screenshot. Now onclick of a button, I want to dynamically add another view like Image(2) in below screenshot to existing view resulting into some like Image(3) in below screenshot. If onclick is clicked again, Image(2) will be added to existing view resulting into something like Image(4) . How do I achieve this? By searching, I found that it required something like LayoutInflater.addView() like this

How to display a TextView from another layout

别等时光非礼了梦想. 提交于 2019-12-06 07:33:13
I have a mainactivity layout and another layout with a textview. I want to set value to textview from my mainactivity file and display it in the mainlayout file. How can I go about this. I'm using layout inflator and am getting the refrence id of Textview successfully. Main Activity: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View vi = inflater.inflate(R.layout

Layout not being inflated in android custom component

偶尔善良 提交于 2019-12-06 03:44:20
问题 I'm getting a null pointer exception in my custom view (which is derived from a LinearLayout ) because it can't find its child views. Here is the code: public class MyView extends LinearLayout { public MyView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MyView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } private TextView mText; @Override protected void onFinishInflate() { super.onFinishInflate(); mText = (TextView)

Create or inflate views programmatically in a RecyclerView OnCreateViewHolder

雨燕双飞 提交于 2019-12-05 21:49:47
Basically I wanted to create a layout or inflate a layout programatically with a RecyclerView , but was unable to do so. As I know how to do with xml by inflating it, but out of curiosity I wanted to do it programatically. My adapter code is as follows: public class ACShare extends RecyclerView.Adapter<ACShare.VHShare>{ private List<Integer> listDrawalbe; public ACShare(Context context) { TypedArray drawables = context.getResources().obtainTypedArray(R.array.s_array_contact_us_share); listDrawalbe=new ArrayList<>(); for (int i = 0; i < drawables.length(); ++i) listDrawalbe.add( drawables

Android Menu item font using LayoutInflaterCompat.setFactory

别来无恙 提交于 2019-12-05 20:06:52
I'm trying to change font of Menu items. According to this answer , I'm using LayoutInflaterCompat.setFactory (support library 22.1.1 is used in my project). My code looks like this: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_income_mail, menu); mFilterMenu = menu.getItem(1).getSubMenu(); final LayoutInflater inflaterCopy = getLayoutInflater().cloneInContext(this); LayoutInflaterCompat.setFactory(inflaterCopy, new LayoutInflaterFactory() { @Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { //

Programmatically add Views inside a (Linear)Layout (that is inside a ScrollView)

核能气质少年 提交于 2019-12-05 16:32:50
I have an app that, after some clicking, shows activity with news contents. I want at a bottom of that to show comments, which are dynamically loaded in async task. One approach is to use ListView and custom ArrayAdapter, but, i would have to put ListView inside a ScrollView, and it is is a problem, even if i manually override ListView's height. It shows one list item, and one part of the following one. The other approach is to define LinearLayout as a holder for comments, than inflate another LinearLayouts defined in it's own xml file, populate it's contents, attach to holder's view. It works