I am new to android. I have a layout that contains an imageview and a textview. I also have a list that contains some data information.
I would like to add the list in the dialog on the textview position. Imageview is set to a default image and I would like to leave it like that for the momenet. Later i will have a new list with imageview that I would like to set to my imageview from the layout.view pos.
I would like to ask how to set the list data to the textview and also how to obtain the clicked element from the dialog
I don't know how to add the list in the dialog on the text
builder = new AlertDialog.Builder(getApplicationContext());
LayoutInflater li = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View promptsView = li.inflate(R.layout.contact_filster_list,(ViewGroup) findViewById(R.id.layout_root));
builder.setView(promptsView);
final ImageView userInput = (ImageView) promptsView.findViewById(R.id.dialog_icon);
final TextView userInput1 = (TextView) promptsView.findViewById(R.id.dialog_text);
Related
Hello i am developing one app where i want to inflate layout in my Card view fro existing layout.And i want to show list of text view dynamically according to my string array.
Here is my existing layout
and i want to inflate following layout in last cardview of above layout
so tried with coding to do it but it display only one textview
my coding is as follows
But it is not working it display only one textview
i want to add textview dynamically according to my string size
I want to inflaate layout just like listview but i dont want to use listview.i want to implement this without listview dynamically
it display only one textview i want to add textview dynamically
according to my string size
Probably due to inflating inflate_specification every time for each TextView and initializing container inside for-loop.
Do it as :
LinearLayout container = (LinearLayout)findViewById(R.id.temp);
LayoutInflater inflater = (LayoutInflater) getApplicationContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(int i=0;i<5;i++)
{
View view = inflater.inflate(R.layout.inflate_specification, container,false);
// Create TextView
TextView product = (TextView)view.findViewById(R.id.speci);
product.setText("i= " + i);
container.addView(view);
}
Try this code:
LinearLayout container = (LinearLayout)findViewById(R.id.temp);
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
container.removeAllViews();
for(int i=0;i<5;i++) {
View view = inflater.inflate(R.layout.inflate_specification, container,false);
// Create TextView
TextView product = (TextView)findViewById(R.id.speci);
product.setText("i= " + i);
container.addView(view);
}
So far I have been able to add a few LinearLayouts to another LinearLayout using this bit of code:
setContentView(R.layout.view_editscore);
ViewGroup container = (ViewGroup) findViewById(R.id.container1);
for (String s : PlayersActivity.playersList) {
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.edit_duplicate, null);
TextView tv = (TextView) view.findViewById(R.id.userName);
tv.setText(s);
container.addView(view);
}
And then I am also able to fill a custom AlertDialog with the R.layout.view_editscore View using this code:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.editScore);
LayoutInflater in = getLayoutInflater();
builder.setView(in.inflate(R.layout.view_editscore, null));
But for some reason, when I use the setView() to put the R.layout.view_editscore in the AlertDialog it only adds the version that was the "outer shell" before I added each of the LinearLayouts.
I have tried building the custom AlertDialog both before and after I fill the View with the other LinearLayouts but both ways are still yielding the same result.
What could I be doing wrong?
How can I inflate several same layouts with diffrent texts and images? I tried use this code
for (final Tour t : info.tours) {
final LinearLayout list = (LinearLayout) findViewById(R.id.tours_list);
Log.d(Const.LOG_TAG, "Add child view to tours_list");
final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View child = inflater.inflate(R.layout.tour_item_for_guide_info,
list, true);
final ImageView tourImage = (ImageView) findViewById(R.id.tour_image);
final String tourImgUrl = Const.HOST + t.image;
imageLoader.DisplayImage(tourImgUrl, tourImage);
TextView tourText = (TextView) findViewById(R.id.text);
tourText.setText(t.name);
}
but text and image setted in first inflated layout, replacing the previous text and image. I understand what it's happens because layouts have same ids. Can I resolve it? I know about ListView and adapters, but I would like to learn if it might be done without them.
I assume that the ImageView and TextView - tourImage, tourText - are elements of R.layout.tour_item_for_guide_info.
If this is so, then when you reference it, you should use the child view to get them.
With other words, instead of:
ImageView tourImage = (ImageView) findViewById(R.id.tour_image);
TextView tourText = (TextView) findViewById(R.id.text);
You should have:
ImageView tourImage = (ImageView)child.findViewById(R.id.tour_image);
TextView tourText = (TextView)child.findViewById(R.id.text);
Not sure if this will definetly fix your problem, but it looks like a bug.
I have a custom dialog that I set up as a function:
public void customDialog(Bitmap bm, String title){
TextView dialogtext = (TextView)findViewById(R.id.layout_root);
//For above also tried r.id.popup which is the containing file for the layout
ImageView dialogimage = (ImageView)findViewById(R.id.popupimage);
dialogtext.setText(title);
dialogimage.setImageBitmap(bm);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.popup, (ViewGroup) findViewById(R.id.layout_root));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.show();
}
The dialog fails whenever I try to set the XML fields dynamically with a Null Pointer Exception. I'm stumped, any ideas? Do I have to add something to the manifest for a custom dialog?
do this first:
View layout = inflater.inflate(R.layout.popup, (ViewGroup) findViewById(R.id.layout_root));
Then, after you define layout, do this:
ImageView dialogimage = (ImageView) layout.findViewById(R.id.popupimage);
Call findViewByID() on the new layout you created, not on the parent content view.
So two changes: Ordering, and layout.findView not findView
I have a ListActivity which shows list of items. I prepared another layout for detailed view that contains items' name, address, phone number and image. I want to show these items detailed in a popup window if one is clicked without closing my ListActivity.
How can i do that?
You can use AlertDialog to do this. Look here http://developer.android.com/guide/topics/ui/dialogs.html. And scroll to Creating a Custom Dialog. Example is:
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
You can use a quickAction like the Twitter app or start a new Activity with android:theme="#android:style/Theme.Dialog" specified in your manifest.
Creating dialogs is described on this page: http://developer.android.com/guide/topics/ui/dialogs.html