android


How to get the content of dynamic layouts in android


**
here is the image
I have parsed an XML file and inflated in dynamic layouts. On clicking
on any layout a dialog fragment opens, but I'm unable to detect which layout
has been selected. I want to get the text view in that layout to pass
in dialog fragment invoked by clicking on the layout. I tried to setId(count),
but when I get id on click listener it gives id of the last layout. Please edit my code or any link with details as I am a beginner. 2
**
//code of fragment is below:
package com.appknoll.studentdatacollection.midwayapp;
import android.app.ActionBar;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Attributes;
public class FragmentOne extends Fragment {
public static FragmentOne newInstance(){
return new FragmentOne();
}
List<XMLParserObject> posts = null;
XMLParser parser = new XMLParser();
ViewGroup layout;
GridView gridView;
GridViewCustomAdapter gridViewCustomAdapter;
List<Attributes.Name> name = new ArrayList<Attributes.Name>();
public static final int PICKER = 1;
Integer id;
String lo;
String size;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_one, container, false);
layout=(ViewGroup)rootView.findViewById(R.id.mainLayout);
layout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Toast.makeText(getActivity(),""+getTag(),Toast.LENGTH_SHORT).show();
FragmentTransaction ft = getFragmentManager().beginTransaction();
FragmentManager fm = getActivity().getSupportFragmentManager();
DFragment dialogFragment = new DFragment ();
Bundle args = new Bundle();
args.putString("item_name",lo);
dialogFragment.setArguments(args);
Toast.makeText(getActivity(),""+id, Toast.LENGTH_LONG).show();
dialogFragment.setTargetFragment(dialogFragment, PICKER);
dialogFragment.show(fm, "Sample Fragment");
ft.commit();
}
});
try {
posts = parser.parse(getActivity().getAssets().open("rt_items.xml"));
//posts = parser.parse(getActivity().getAssets().open("rt_images"));
int count = 0;
for (XMLParserObject post : posts) {
String name2=post.getName().toString();
if(contains( name2, "Sushi" )) {
count++;
LinearLayout lii = new LinearLayout(this.getContext());
lii.setLayoutParams(new LinearLayout.LayoutParams(600, 800));
//lii.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
lii.setPadding(10, 10, 10, 10);
lii.setId(count);
id= lii.getId();
//Toast.makeText(getActivity(), ""+id, Toast.LENGTH_SHORT).show();
lii.setTag(post.getName());
//Toast.makeText(getActivity(),""+lii.getTag(), Toast.LENGTH_SHORT).show();
lii.setBackgroundResource(R.drawable.border);
lii.setOrientation(LinearLayout.VERTICAL);
layout.addView(lii);
TextView name = new TextView(this.getContext());
name.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
name.setText(post.getName());
name.setTextSize(30);
name.setTextColor(Color.parseColor("#191970"));
lii.addView(name);
TextView Price = new TextView(this.getContext());
Price.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
Price.setText(Integer.toString(post.getUnit_price()) + "/-");
Price.setTextSize(40);
Price.setTextColor(Color.parseColor("#FF0000"));
lii.addView(Price);
TextView description = new TextView(this.getContext());
description.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
description.setText(post.getDescription());
description.setTextSize(15);
description.setTextColor(Color.parseColor("#000000"));
lii.addView(description);
ImageView image = new ImageView(this.getContext());
String image2 = post.getName().toString();
if (contains(image2, "1")){
image.setImageResource(R.drawable.sushiroll1);
} else if(contains(image2, "2")){
image.setImageResource(R.drawable.sushiroll2);
}else if(contains(image2, "3")){
image.setImageResource(R.drawable.sushiroll3);
}
lii.addView(image);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rootView;
}
public boolean contains( String haystack, String needle ) {
haystack = haystack == null ? "" : haystack;
needle = needle == null ? "" : needle;
return haystack.toLowerCase().contains( needle.toLowerCase() );
}
}

Related Links

Android - See where app size comes from
How to access TextView on top of a View
Android native client fails to connect to Worklight
Click on ImageButton from included layout doesn't work
In RxJava, how do I start a potentially infinite stream of events generated from an API?
“recipe commences before first target” error during “make” command while building Android
Errors when trying to jump to another page
Custom ListView filtering on attributes from menu
Can not play a mp4 video in android VIdeoview from a remote url
Shape with only one transparent border
Attribute textAllCaps has already been defined
How to provide dagger dependency for other fragments?
Android Google Play / Drive Api
How connect wear emulator and phone emulator?
Date separators while scrolling in ListView
getPreferences always returns default value

Categories

HOME
service-worker
assembly
microsoftgraph
google-spreadsheet
battery
solaris
shiro
pdfbox
switch-statement
rds
emscripten
3d-reconstruction
vsm
crystal-reports-2013
trac
discrete-mathematics
openpyxl
plist
selenium-ide
mongodb-csharp
microsoft-dynamics-nav
mvc-mini-profiler
wolframalpha
nodemcu
enterprise-miner
simpleitk
r-mice
aggregation
maze
licensing
oculus
apktool
fractions
handler
winexe
errbot
user-defined-functions
sqlpackage
google-cast
mockjax
deltaspike
jmockit
git-squash
parse-tree
cin
attributeerror
escpos
ssrs-2014
apache-spark-dataset
facebook-social-plugins
procfile
dynamic-linq
opennms
linter
configurationmanager
activeperl
manova
sundials
reshape
template-toolkit
pybrain
google-photos
vcloud-director-rest-api
cudd
custom-lists
flex-monkey
reporting-services-2012
async.js
eigenvector
shopping
cda
beanstalk
thread-sleep
kendo-upload
flock
viola-jones
qtwebengine
dbaccess
uncaught-typeerror
android-vibration
iso-prolog
strawberry-perl
angular-carousel
mintty
lnk
gnumeric
authlogic
dsym
away3d
flex++
poker
jquery-1.9
apache-abdera
twisted.web
android-loadermanager
midlet
usertype
isa-swizzling
denied
user-tracking
umra
socketserver
mtu
diagrams
drupal-fivestar
pos-for-.net
django-piston
fail-fast-fail-early
software-lifecycle

Resources

Encrypt Message