I am developing Splash screen,GridView, ListView and 4 other codes.
Since every item click in GridView namely Image,video,document and upload displays the same items in ListView(my code is like that) I am confused as to how to apply the loops in the onItemClick(AdapterView parent, View view, int position, long id) method so that i can display image code,video code,document code and uploading code in accordance with the items in GridView and ListView
To be very precise just go through the flow below
1.Image(Grid View)-----Onclick---->Item1(listview)--Onclick()-->Image Code
---->Item2(listview)--Onclick()-->Image Code
---->Item3(listview)--Onclick()-->Image Code
---->Item4(listview)--Onclick()-->Image Code
2.Video(Grid View)-----Onclick---->Item1(listview)--Onclick()-->Video Code
---->Item2(listview)--Onclick()-->Video Code
---->Item3(listview)--Onclick()-->Video Code
---->Item4(listview)--Onclick()-->Video Code
3.Document(Grid View)-----Onclick---->Item1(listview)--Onclick()-->Document Code
---->Item2(listview)--Onclick()-->Document Code
---->Item3(listview)--Onclick()-->Document Code
---->Item4(listview)--Onclick()-->DocumentCode
4.Upload(Grid View)-----Onclick---->Item1(listview)--Onclick()-->Upload Code
---->Item2(listview)--Onclick()-->Upload Code
---->Item3(listview)--Onclick()-->Upload Code
---->Item4(listview)--Onclick()-->UploadCode
Thanks in advance if anybody could help it would be fantastic
If your grid screen and list screen are seperate activities, then you can pass the "type" of the grid option that was selected by the user as an extra in the intent you are using to start the list activity. And then depending on this value, you can decide the action that is to be taken in the onItemClick.
Hope that helps.
Define the types for your operations. like,
public static final int OPTION_IMAGECODE = 1 ;
public static final int OPTION_VIDEOCODE = 2 ; ...etc
and a varaible to hold the type like, private int selectedGridOption ;
When user clicks on the grid option, populate the variable. Like,
selectedGridOption = OPTION_IMAGECODE ; if the user selectes the image type.
In your intent you use to start the list activity put this value as an extra. Like,
listActivityIntent.putExtra("Selected Option", selectedGridOption) ;
In you list activity you can retreive this value as,
getIntent().getIntExtra("Selected Option", *default_value_you_want*) ;
Related
I want make a clickable and scrollable list of images. When image is clicked it should appear appropriate string in TextView.
I have list of Object which have images id and string id in itself:
public class MyClass implements Serializable {
private int imageId;
private int stringId;
//(...)
}
public ArrayList<MyClass> listOfObjects = new ArrayList<MyClass>();
How it is best to do? I do not know too much to go about it.
Thanks in advance.
PS: Sorry for my bad english.
You have to implement a custom list view. The list view shall consist of a custom layout, in which every line consists of a button. Then, you can assign each imageId to the buttons. Then, it can display the related text using the same index in the list.
how to creat a Arraylist adapter which will change the view based on a flag in the LISTVIEW, Flag can be IMAGE , IMAGETEXT, VIDEO , VIDEOTEXT, TEXT
e.g like in facebook post , 1. if a friend posts a text, list row will only contain a text with his Name
2. if a friend posts a Image , list row will only contain a image with his Name
3. if a friend poasts a Video , list row will only contain a Video with his Name , and only Video onClick() ,
Playing that Video in a external Player
Flag = text. view to be attached is text.xml
Flag = Video, View to be attached is video.xml
Flag = Image ,View to be attached is image.xml
ANY HELP ON THIS.
Thanks in Advance...
override getItemViewType(int position) and getViewTypeCount() method in your adapter and
inflate you view according to it from getView(). In you case write methods like
#Override
public int getItemViewType(int position) {
if(list.get(position).flag == text)
return 0;
else if(list.get(position).flag == image)
return 1;
else
return 2;
}
#Override
public int getViewTypeCount() {
return 3;
}
I am not pretty much sure but it's my concept that firstly create a layout for row that can hold every thing that you want show(image, video, text etc ). And make this layout such a way if one thing is not present then it automatically wrapped(means if video is not present then video space will not be there).
Now make json of every list row and pass it to Adapter of list. Then override getView() method of the
adapter and parse json there and display according to your layout.
i implemented similar Custom Adapter for ListView which is used in this link , also used ViewHolders
check this link
http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/
I am creating one view from XML, I have defined one row in xml and in my main layout I am adding it through layout inflator and setting the id's of component( TextView, EditText, Button) run time. I have three requirements
User can add new row( It is done)
User can delete row ( It is done
I need to fetch the data from the created row. ( It is done too)
I am following this tutorial
https://github.com/laoyang/android-dynamic-views#readme and it is great tutorial as well.
I am creating the ID of each component at run time and adding it to arraylist so that I can fetch the data from it through loop. i.e
for (EditText editText : Quanitity) { }
Problem is that when user presses the delete button on each row, It deletes the row from the layout and its components as well through this code:
Main.removeView((View) v.getParent());
but its corresponding components ID's are already added to the arraylist. I want when user presses the delete button of the row I should get the position of it so that I can remove it through the arraylist as well.
Each row has a textview which is spinner style. I want to open the spinner on click of textview and value should be set for that Textview not all rows.
Please help me in this case. I am really stucked and deadline is today.
Thanks
aray
First thing to achieve this is to get your selected view's ID and after that search the arraylist for that id and if found delete it.That should look something similar to this :
int myEditTextID = myEditText.getId(); // ids of your selected editext
ids.remove(ids.indexOf(myEditTextID)); // ArrayList<Integer> where you are storing your ids.
The code above first get the id of your selected edittext and than search for the it's index in your arraylist and remove it.
That's all! : )
You can get the index of the child in the ViewGroup with indexOfChild(View). You may need to subtract an offset from that index depending on how many child views come before the rows you are adding (if any).
http://developer.android.com/reference/android/view/ViewGroup.html#indexOfChild(android.view.View)
public void onDeleteClicked(View v) {
// get index
int index = mContainerView.indexOfChild((View) v.getParent()) - offset;
// remove from ArrayList
myArrayList.remove(index);
// remove the row by calling the getParent on button
mContainerView.removeView((View) v.getParent());
}
You can get the offset by storing the initial index of the ViewGroup that you will be adding the views (rows) at before you add any. Which, in the case of the link provided (although unnecessary since it equals 0), would be something like this:
private int offset = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
...
// this should be equal to the index where the first row will be inserted
// offset = 0 with the code in your link
offset = mContainerView.getChildCount() - 1;
// Add some examples
inflateEditRow("Xiaochao");
inflateEditRow("Yang");
}
I am working on a CRM app in android, in which, I am showing details of all contacts in a list view. Now, my requirement is when I click on a particular item in the list, it should only display the details about selected contact, such as, name, address, email, etc.. The data is coming from XML file, which I am parsing using SAX Parser. How can I query a XML to get selected data?
You are filling the ListView using Adapter right? Now you can get the item at the selected view inside the ListView and pass this item to an Activity.
E.g. inside your Adatper class implement the onItemClickListener:
public void onItemClick(AdapterView<?> a, View v, int position, long l) {
// Remembers the selected Index
Data item =getItem(position);
Intent intent = new Intent(getApplicationContext(), DetailedActivity.class);
intent.put("object",item);
startActivity(intent);
}
Note: the item "Data" class should implement the Parsable interface so it can be passed to the Activity in your DetailedActivity onCreate method get that object and update the UI based on its Values.
I have a list view with over 100 items. Each of these items show description when clicked on them. The problem is that I don't want over a hundred activities to display the description of each item instead I want to implement a single activity which refreshes the whole view and sets it to the new data depending upon the item clicked.How can I achieve this?
Thank you.
Create a new activity that only displays the details of your selected item. This activity is created for each item but you would open it, press the back button open it again with different content. Have a look at Intent and their extras as how to pass the data to your details activity.
try like this
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i=new Intent(yourActivity.this,next.class);
String s = this.getListAdapter().getItem(position);
//query the database for the row with this string.. and get the necessary information
i.putExtra("name",s1);
i.putExtra("id",s2);
startActivity(i);
}