I have a list view and I want to show some values inside it, the connection is made without any error, but my list view doesn't show those values, I don't know what I did wrong, my code is below please help me. I think I have done some wrong in the customeadapter.. please check my custom adapter CustomAdapterViewDriver.
My Activity
public class PerformBargain extends ActionBarActivity {
ListView UserDetails;
JSONArray jsonArray;
SendPostRequest mSendPostRequest;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_perform_bargain);
UserDetails=(ListView)findViewById(R.id.UserDetails);
mSendPostRequest= new SendPostRequest();
mSendPostRequest.execute();
}
class SendPostRequest extends AsyncTask<Void, Void, JSONArray>
{
String postData = "";
HttpURLConnection httpURLConnection= null;
#Override
protected JSONArray doInBackground(Void... params) {
try {
Bundle bundle=getIntent().getExtras();
String id=bundle.getString("ID");
httpURLConnection= (HttpURLConnection) new URL("http://192.168.0.14:8080/GoodsServer/ViewRideDetails.jsp").openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
DataOutputStream outputStream= new
DataOutputStream(httpURLConnection.getOutputStream());
outputStream.writeBytes("id=" +id);
outputStream.flush();
outputStream.close();
InputStream in = httpURLConnection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(in);
int inputStreamData = inputStreamReader.read();
while (inputStreamData != -1) {
char currentData = (char) inputStreamData;
inputStreamData = inputStreamReader.read();
postData += currentData;
}
jsonArray=new JSONArray(postData.trim());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpURLConnection!= null) {
httpURLConnection.disconnect();
}
}
return jsonArray;
}
#Override
protected void onPostExecute(JSONArray s) {
Toast.makeText(getApplicationContext(),postData,Toast.LENGTH_LONG).show();
try{
CustomAdapterViewDriver customAdapterViewDriver=new CustomAdapterViewDriver(PerformBargain.this,s);
UserDetails.setAdapter(customAdapterViewDriver);
}catch (Exception e)
{
System.out.print(e);
}}
}
CustomAdapterViewDriver Class
class CustomAdapterViewDriver extends BaseAdapter implements ListAdapter {
String ids;
TextView name,email,phone,Source,destination;
private final Activity activity;
private final JSONArray jsonArray;
public CustomAdapterViewDriver(Activity activity, JSONArray jsonArray) {
assert activity != null;
assert jsonArray != null;
this.jsonArray = jsonArray;
this.activity = activity;
}
#Override public int getCount() {
return jsonArray.length();
}
#Override public JSONObject getItem(int position) {
return jsonArray.optJSONObject(position);
}
#Override public long getItemId(int position) {
JSONObject jsonObject = getItem(position);
return jsonObject.optLong("id");
}
#Override public View getView(int position, View view, ViewGroup parent) {
if (view == null)
view = activity.getLayoutInflater().inflate(R.layout.userviewforbargain, null);
JSONObject jsonObject = getItem(position);
name=(TextView)view.findViewById(R.id.namevu);
phone =(TextView)view.findViewById(R.id.phone);
email=(TextView)view.findViewById(R.id.email);
Source=(TextView)view.findViewById(R.id.sourceadderss);
destination=(TextView)view.findViewById(R.id.destinationaddress);
try{
name.setText(jsonObject.getString("Name"));
phone.setText(jsonObject.getString("Phone"));
email.setText(jsonObject.getString("Email"));
Source.setText(jsonObject.getString("Source"));
destination.setText(jsonObject.getString("DestAdd"));
}catch(Exception e)
{
System.out.print(e);
}
return view;
}
}
userviewforbargain Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Name"
android:textColor="#000"
/>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Phone"
android:textColor="#000"
/>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Email"
android:textColor="#000"
/>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="SourceAdderss"
android:textColor="#000"
/>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Destination"
android:textColor="#000"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="50dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="#+id/namevu"
android:hint="Name"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:hint="Phone"
android:id="#+id/phone"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:hint="Email"
android:id="#+id/email"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:hint="sourceadderss"
android:id="#+id/sourceadderss"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:hint="Destination"
android:id="#+id/destinationaddress"
android:textColor="#000"
/>
</LinearLayout>
</LinearLayout>
the problem was with my XML file... I just add a relative layout to my XML and its working fine now.
code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.user.good_carriermacfast.PerformBargain"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="110dp"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Name"
android:textColor="#000"
/>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Phone"
android:textColor="#000"
/>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Email"
android:textColor="#000"
/>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="SourceAdderss"
android:textColor="#000"
/>
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Destination"
android:textColor="#000"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="110dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="#+id/namevu"
android:hint="Name"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:hint="Phone"
android:id="#+id/phone"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:hint="Email"
android:id="#+id/email"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:hint="sourceadderss"
android:id="#+id/sourceadderss"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:hint="Destination"
android:id="#+id/destinationaddress"
android:textColor="#000"
/>
</LinearLayout>
</RelativeLayout>
Related
I want a listview in a tabhost. My data is coming from the database. Through retrofit, I am getting 3 records from the database. I am passing these 3 records to the ListView Adapter that I have created. These records are coming till the constructor of Adapter but after that in the getView method only 1 record is accessed 3 times. I am not sure why this is happening.
This is my Post Activity:
public static final ArrayList<WorkProfilePojo> mProfiles = new ArrayList<>();
BaseURL baseURL = new BaseURL();
VendorPostAdapter pAdapter;
ListView mPostList;
public List<WorkProfilePojo> returnedList = new ArrayList<>();
String lv_vendorId = null;
public static String lv_name;
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
lv_vendorId = intent.getStringExtra("lv_vendorId");
Log.e("vendor id", lv_vendorId);
lv_name = intent.getStringExtra("lv_name");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
getRetrofit();
}
private void getRetrofit() {
Retrofit retrofit = new RetrofitObject().getRetrofit();
final WorkProfileforPostTabAPI mProfileAPI =
retrofit.create(WorkProfileforPostTabAPI.class);
final Call<ArrayList<WorkProfilePojo>> mCall =
mProfileAPI.getWork(lv_vendorId);
mCall.enqueue(new Callback<ArrayList<WorkProfilePojo>>() {
#Override
public void onResponse(Call<ArrayList<WorkProfilePojo>> call,
Response<ArrayList<WorkProfilePojo>> response) {
mProfiles.clear();
returnedList = (ArrayList<WorkProfilePojo>)response.body();
WorkProfilePojo wp;
Log.e("Teste2",
returnedList.get(0).getLv_eventSubCategory());
for (int i = 0; i<= returnedList.size()-1; i++){
wp=new WorkProfilePojo();
wp.setLv_vendorWorkId(returnedList.get(i).getLv_vendorWorkId());
wp.setLv_eventSubCategory(returnedList.get(i).getLv_eventSubCategory());
wp.setLv_workDescription(returnedList.get(i).getLv_workDescription());
wp.setLv_numWorkLikes(returnedList.get(i).getLv_numWorkLikes());
wp.setLv_numWorkComments(returnedList.get(i).getLv_numWorkComments());
mProfiles.add(wp);
Log.e("retrofit profile size: ",
String.valueOf(mProfiles.size()));
populateListView(mProfiles);
}
#Override
public void onFailure(Call<ArrayList<WorkProfilePojo>> call,
Throwable t) {
Log.e(TAG, "FAIL");
}
});
}
private void populateListView(ArrayList<WorkProfilePojo> mProfiles) {
mPostList = (ListView) findViewById(R.id.listVPost);
Log.e("func prof size: ", String.valueOf(mProfiles.size()));
pAdapter = new VendorPostAdapter(this, mProfiles, lv_name);
mPostList.setAdapter(pAdapter);
}
This is my Adapter:
public class VendorPostAdapter extends BaseAdapter {
Context context;
ArrayList<WorkProfilePojo> lv_profiles = new ArrayList<>();
String lv_name;
LayoutInflater inflater;
public VendorPostAdapter(Context context, ArrayList<WorkProfilePojo>
lv_profiles, String lv_name){
this.context = context;
this.lv_profiles =lv_profiles;
this.lv_name = lv_name;
Log.e("adapter name", lv_name );
Log.e("adapter workid", lv_profiles.get(0).getLv_vendorWorkId());
Log.e("adapter workid", lv_profiles.get(1).getLv_vendorWorkId());
Log.e("adapter workid", lv_profiles.get(2).getLv_vendorWorkId());
}
private class ViewHolder {
TextView mtxtViewPartnerName;
TextView mtxtViewEventCategory;
TextView mtxtViewDate ;
TextView mtxtViewFillDescription;
GridView mgrdViewPhotos ;
ImageView mimgLike ;
ImageView mimgPostProfilePic ;
ImageView mimgShare ;
ImageView mimgComment ;
ImageView mimgLikeThumb ;
TextView mtxtNoOfLikes ;
TextView mtxtNoOfComments ;
TextView mtxtComments;
}
#Override
public int getCount() {
return lv_profiles.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
inflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.content_post, parent,
false);
holder = new ViewHolder();
holder.mtxtViewPartnerName = (TextView)
convertView.findViewById(R.id.txtViewPartnerName);
holder.mtxtViewEventCategory= (TextView)
convertView.findViewById(R.id.txtViewEventCategory);
holder.mtxtViewDate = (TextView)
convertView.findViewById(R.id.txtViewDate);
holder.mtxtViewFillDescription = (TextView)
convertView.findViewById(R.id.txtViewFillDescription);
holder.mgrdViewPhotos = (GridView)
convertView.findViewById(R.id.grdViewPhotos);
holder.mimgLike = (ImageView)
convertView.findViewById(R.id.imgLike);
holder.mimgPostProfilePic = (ImageView)
convertView.findViewById(R.id.imgPostProfilePic);
holder.mimgShare = (ImageView)
convertView.findViewById(R.id.imgShare);
holder.mimgLikeThumb = (ImageView)
convertView.findViewById(R.id.imgLikeThumb);
holder.mimgComment = (ImageView)
convertView.findViewById(R.id.imgComment);
holder.mtxtNoOfLikes = (TextView)
convertView.findViewById(R.id.txtViewNoOfLikes);
holder.mtxtNoOfComments = (TextView)
convertView.findViewById(R.id.txtViewNoOfComments);
holder.mtxtComments = (TextView)
convertView.findViewById(R.id.txtViewComments);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
final WorkProfilePojo wp = lv_profiles.get(position);
Log.e("getView name", lv_name );
Log.e("getView workid",
lv_profiles.get(position).getLv_vendorWorkId());
holder.mtxtViewPartnerName.setText( lv_name );
holder.mtxtViewEventCategory.setText( wp.getLv_eventSubCategory() );
FormatDate lv_date = new FormatDate();
holder.mtxtViewDate.setText(lv_date.formatDayMonDateYr(wp.getLv_creationDate()));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription());
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription());
holder.mimgLikeThumb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,
VendorWorkLikesActivity.class);
intent.putExtra("lv_workId", wp.getLv_vendorWorkId());
Log.e("postad workid", wp.getLv_vendorWorkId());
context.startActivity(intent);
}
});
holder.mtxtComments.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,
VendorWorkCommentActivity.class);
context.startActivity(intent);
}
});
return convertView;
}
}
This is my activity_post.xml wrapped in relative layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundcolour"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="1"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
/>
</RelativeLayout>
This is my content_post for line item wrapped in relative layout:
<RelativeLayout
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgPostProfilePic"
android:src="#drawable/profileicon"
android:layout_width="60dp"
android:layout_height="60dp" />
<TextView
android:id="#+id/txtViewPartnerName"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_toEndOf="#id/imgPostProfilePic"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:text="partner Name" />
<TextView
android:id="#+id/txtViewManageWork"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="140dp"
android:layout_marginTop="5dp"
android:text="Managed" />
<TextView
android:id="#+id/txtViewEventCategory"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="220dp"
android:paddingRight="5dp"
android:layout_marginTop="5dp"
android:text="" />
<TextView
android:id="#+id/txtViewEvent"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_toEndOf="#id/txtViewEventCategory"
android:layout_marginTop="5dp"
android:text="Event" />
<TextView
android:id="#+id/txtViewDate"
style="#style/InputLable"
android:layout_width="100dp"
android:layout_height="25dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
android:text="Date" />
<TextView
android:id="#+id/txtViewDescription"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="80dp"
android:text="Work Description" />
<TextView
android:id="#+id/txtViewFillDescription"
style="#style/InputLable"
android:layout_width="330dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="100dp"
android:text="XYZ" />
<TextView
android:id="#+id/txtViewPhotos"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="130dp"
android:text="Photos" />
<GridView
android:id="#+id/grdViewPhotos"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:numColumns="auto_fit"
android:layout_below="#id/txtViewPhotos">
</GridView>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:id="#+id/divider"
android:background="#color/colorDarkGray"
android:layout_below="#id/grdViewPhotos"
android:layout_weight="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dividerlayout"
android:orientation="horizontal"
android:layout_below="#id/divider"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<ImageView
android:id="#+id/imgLikeThumb"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_below="#id/grdViewPhotos"
android:clickable="true"
android:src="#drawable/likethumb" />
<TextView
android:id="#+id/txtViewNoOfLikes"
style="#style/InputLable"
android:layout_width="30dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:textAlignment="center"
android:layout_marginTop="5dp"
android:text="0" />
<TextView
android:id="#+id/txtViewNoOfComments"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="5dp"
android:textAlignment="center"
android:text="0" />
<TextView
android:id="#+id/txtViewComments"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:text="Comments" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:id="#+id/divider1"
android:background="#color/colorDarkGray"
android:layout_below="#id/dividerlayout"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dividerlayout1"
android:layout_below="#id/dividerlayout"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/imgLike"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#id/divider1"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/likeicon2" />
<TextView
android:id="#+id/txtViewLike"
style="#style/InputLable"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Likes" />
<ImageView
android:id="#+id/imgShare"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="60dp"
android:layout_below="#id/divider1"
android:layout_centerInParent="true"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/shareicon3" />
<TextView
android:id="#+id/txtViewShare"
style="#style/InputLable"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Share" />
<ImageView
android:id="#+id/imgComment"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="45dp"
android:layout_below="#id/divider1"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/commenticon" />
<TextView
android:id="#+id/txtViewComment"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Comment" />
</LinearLayout>
</RelativeLayout>
From retrofit results, I am getting 3 records from database:
func workid:: W00000000000013
func workid:: W00000000000014
func workid:: W00000000000015
But in getView() method I am getting only 1 record coming 3 times:
Likesad name: W00000000000013
Likesad name: W00000000000013
Likesad name: W00000000000013
holder.mtxtViewDate.setText(lv_date.formatDayMonDateYr(wp.getLv_creationDate(getPostion())));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription(getPostion()));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription(getPostion()));
This Might work.
I'm making a form. I've already done saving my data into database. Now I've done displaying specific data (code of form and date) to differentiate my forms into the list view. And when user click on item it will start pre-define activity and fill the columns with corresponding data.
For example: user sees 5 rows of list view items. He clicks on the second row and it will show the activity fill with corresponding data with this row. But when he clicks on the third row it will show in same activity different data.
I've been trying for several days but i can't figured it out. I'm android beginner so it's almost impossible for me to do it on my own. So i would be very grateful for every help.
Here are same code's hope it's suffice.
DataListActivity
public class DataListActivity extends AppCompatActivity {
ListView listView;
SQLiteDatabase sqLiteDatabase;
DbOperace dbOperace;
Cursor cursor;
ListDataAdapter listDataAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_list_layout);
listView = (ListView) findViewById(R.id.lis_view);
listDataAdapter = new ListDataAdapter(getApplicationContext(),R.layout.row_layout);
listView.setAdapter(listDataAdapter);
dbOperace = new DbOperace(getApplicationContext());
sqLiteDatabase = dbOperace.getReadableDatabase();
cursor = dbOperace.getInformations(sqLiteDatabase);
if (cursor.moveToFirst())
{
do {
String kod,den;
kod = cursor.getString(0);
den = cursor.getString(1);
DataProvider dataProvider = new DataProvider(kod,den);
listDataAdapter.add(dataProvider);
}while (cursor.moveToNext());
}
}
}
DataProvider.java
public class DataProvider {
private String kod;
private String den;
public String getKod() {
return kod;
}
public void setKod(String kod) {
this.kod = kod;
}
public String getDen() {
return den;
}
public void setDen(String den) {
this.den = den;
}
public DataProvider(String kod, String den)
{
this.kod=kod;
this.den=den;
}
}
DbOperations
public Cursor getInformations(SQLiteDatabase db)
{
Cursor cursor;
String[] projections = {FormDatabase.FormularovaDatabaze.KOD_USEKU_KOMUNIKACE,
FormDatabase.FormularovaDatabaze.DNE};
cursor = db.query(FormDatabase.FormularovaDatabaze.JMENO_TABULKY,projections,null,null,null,null,null);
return cursor;
}
ListDataAdapter.java
public class ListDataAdapter extends ArrayAdapter{
List list = new ArrayList();
public ListDataAdapter(Context context, int resource) {
super(context, resource);
}
static class LayoutHandler
{
TextView kod,den;
}
#Override
public void add(Object object) {
super.add(object);
list.add(object);
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutHandler layoutHandler;
View row = convertView;
if (row == null)
{
LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.row_layout,parent,false);
layoutHandler = new LayoutHandler();
layoutHandler.kod = (TextView)row.findViewById(R.id.t_kod);
layoutHandler.den = (TextView) row.findViewById(R.id.t_den);
row.setTag(layoutHandler);
}
else
{
layoutHandler=(LayoutHandler) row.getTag();
}
DataProvider dataProvider = (DataProvider) this.getItem(position);
layoutHandler.kod.setText(dataProvider.getKod());
layoutHandler.den.setText(dataProvider.getDen());
return row;
}
}
ActivityWhereIWanttheRetrievedData.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollView"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="jansoldat.formular100.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Úsek komunikace:"
android:id="#+id/textView81"
android:textStyle="bold"
android:textSize="20dp"
android:textColor="#870b0f"
android:layout_marginTop="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText_Usek_komunikace"
android:layout_below="#+id/textView81"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kód úseku komunikace:"
android:id="#+id/textView82"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/editText_Usek_komunikace"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_below="#+id/textView82"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kódy sousedících objektů/ komunikací"
android:id="#+id/textView83"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="na počátku úseku komunikace:"
android:id="#+id/textView84"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/textView83"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/textView81"
android:layout_alignEnd="#+id/textView81"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText3"
android:layout_below="#+id/textView84"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/textView84"
android:layout_alignEnd="#+id/textView84" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="na konci úseku komunikace:"
android:id="#+id/textView85"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/textView83"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/textView86"
android:layout_toEndOf="#+id/textView86"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText4"
android:layout_below="#+id/textView84"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/textView85"
android:layout_alignStart="#+id/textView85" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Součást měřené trasy/ lokality:"
android:id="#+id/textView86"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText5"
android:layout_below="#+id/textView86"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GPS souřadnice"
android:id="#+id/textView87"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/editText5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="počátek měřeného úseku:"
android:id="#+id/textView88"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/textView87"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText6"
android:layout_alignParentStart="true"
android:inputType="numberDecimal"
android:digits="0123456789,.°'"
android:layout_below="#+id/textView88"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="konec měřeného úseku:"
android:id="#+id/textView89"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/editText6"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText7"
android:digits="0123456789,.°'"
android:inputType="numberDecimal"
android:layout_below="#+id/textView89"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mapové schéma:"
android:id="#+id/textView90"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/editText7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:id="#+id/imageView_mapa"
android:contextClickable="false"
android:adjustViewBounds="false"
android:background="#850202"
android:layout_below="#+id/textView90"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Měření provedl(i):"
android:id="#+id/textView91"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/imageView_mapa"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dne:"
android:id="#+id/textView92"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_above="#+id/editText8"
android:layout_toRightOf="#+id/textView86"
android:layout_toEndOf="#+id/textView86" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/editText8"
android:layout_below="#+id/textView91"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/textView88"
android:layout_alignEnd="#+id/textView88" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText9"
android:layout_below="#+id/textView92"
android:layout_alignLeft="#+id/textView92"
android:layout_alignStart="#+id/textView92"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Délka úseku komunikace:"
android:id="#+id/textView93"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText9"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText10"
android:layout_alignParentStart="true"
android:inputType="numberDecimal"
android:digits="0123456789,.m"
android:layout_below="#+id/textView93"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Typ komunikace:"
android:id="#+id/textView94"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/editText10"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Materiál povrchu:"
android:id="#+id/textView95"
android:layout_column="0"
android:textColor="#870b0f"
android:textStyle="bold"
android:layout_below="#+id/radioGroup3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/radioGroup3"
android:layout_below="#+id/textView94"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pás pro pěší (chodník)"
android:id="#+id/radioButton"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stezka pro chodce (označeno značkou C07)"
android:id="#+id/radioButton2"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stezka pro chodce a cyklisty ( označeno značkou C09 nebo C10)"
android:id="#+id/radioButton3"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="nezpevněná komunikace (pěšina, polní cesta...)"
android:id="#+id/radioButton4"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pěší zóna (označeno značkou IP27)"
android:id="#+id/radioButton5"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="obytná zóna (označeno značkou IP26)"
android:id="#+id/radioButton6"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pohyb po motoristické komunikaci (krajnice...)"
android:id="#+id/radioButton7"
android:checked="false" />
</RadioGroup>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner2"
android:layout_below="#+id/textView95"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText11"
android:visibility="visible"
android:layout_below="#+id/spinner2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</ScrollView>
EDIT:
here is my updated code:
DataListActivity.java
public class DataListActivity extends AppCompatActivity {
ListView listView;
SQLiteDatabase sqLiteDatabase;
DbOperace dbOperace;
Cursor cursor;
ListDataAdapter listDataAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_list_layout);
listView = (ListView) findViewById(R.id.lis_view);
listDataAdapter = new ListDataAdapter(getApplicationContext(),R.layout.row_layout);
listView.setAdapter(listDataAdapter);
dbOperace = new DbOperace(getApplicationContext());
sqLiteDatabase = dbOperace.getReadableDatabase();
cursor = dbOperace.getInformations(sqLiteDatabase);
if (cursor.moveToFirst())
{
do {
String kod,den;
kod = cursor.getString(0);
den = cursor.getString(1);
DataProvider dataProvider = new DataProvider(kod,den);
listDataAdapter.add(dataProvider);
}while (cursor.moveToNext());
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(DataListActivity.this, RetrieveData.class);
intent.putExtra("data", listView.getSelectedItemPosition());
startActivity(intent);
}
});
}
}
Retrieve Data
public class RetrieveData extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_retrieve_data);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
DataProvider dataProvider = bundle.getParcelable("data");
}
}
}
How should I now get into the retrieve activity data from database (which are not mention in code before [just in saving])?
You had to write setOnitemclicklistener for the listview. Inside that get that position value from the list. Below is the code for OnItemClickListener,
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(DataListActivity.this, DetailActivity.class);
intent.putExtra("data", list.get(position);
startActivity(intent);
}
});
And in DetailActivity class get the value as shown below.
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
DataProvider dataProvider = bundle.getParcelable("data");
}
In order to achieve this, you had to maintain the List in DataListActivity class itself. Also you had to implement Parcelable in your model class as shown below.
public class DataProvider implements Parcelable {
private String kod;
private String den;
public String getKod() {
return kod;
}
public void setKod(String kod) {
this.kod = kod;
}
public String getDen() {
return den;
}
public void setDen(String den) {
this.den = den;
}
public DataProvider(String kod, String den)
{
this.kod=kod;
this.den=den;
}
protected DataProvider(Parcel in) {
kod = in.readString();
den = in.readString();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(kod);
dest.writeString(den);
}
#SuppressWarnings("unused")
public static final Parcelable.Creator<DataProvider> CREATOR = new Parcelable.Creator<DataProvider>() {
#Override
public DataProvider createFromParcel(Parcel in) {
return new DataProvider(in);
}
#Override
public DataProvider[] newArray(int size) {
return new DataProvider[size];
}
};
}
By this you can achieve easily. Hope this helps:)
I am fetch data using json and set my spinner and I am also want to add radio button in my operator spinner but radio button not visible and not working I want visible button some Ids but its not visible.
MyXML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rount_corner1"
android:layout_margin="#dimen/activity_horizontal_margin"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_marginTop="25dp"
android:inputType="number"
android:maxLength="10"
android:textColor="#000000"
android:layout_marginRight="40dp"
android:hint="Enter Mobile number"
android:textColorHint="#000000"
android:layout_marginLeft="40dp"
android:clickable="true"
android:id="#+id/prenumber"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_marginTop="7dp"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
android:clickable="true"
android:hint="Enter Recharge Amount"
android:textColorHint="#000000"
android:textColor="#000000"
android:maxLength="4"
android:inputType="number"
android:id="#+id/rechergpre"
/>
<Spinner
android:id="#+id/operator_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:gravity="left"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="7dp"
android:prompt="#string/appbar_scrolling_view_behavior">
</Spinner>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="38dp"
android:visibility="gone"
>
<RadioButton
android:id="#+id/_TopUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TopUp "
/>
<RadioButton
android:id="#+id/Special"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Special(2G,3G,SMS,VOICE )"
/>
</RadioGroup>
<Button
android:layout_width="match_parent"
android:id="#+id/prepaid_submit"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:text="Submit"
android:textStyle="bold"
android:layout_marginTop="60dp"
/>
</LinearLayout>
</RelativeLayout>
Mycode in Fragment
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
MyApplication myOpt = (MyApplication)getActivity().getApplicationContext();
protected Void doInBackground(Void... params) {
json_data = new ArrayList<Json_Data>();
datalist = new ArrayList<String>();
oprList = new ArrayList<String>();
jsonobject = JSONfunctions
.getJSONfromURL("http://www.example.com");
Log.d("Response: ", "> " + jsonobject);
try {
jsonarray = jsonobject.getJSONArray("data");
for (int i = 0; i < jsonarray.length(); i++) {
jsonobject = jsonarray.getJSONObject(i);
Json_Data opt_code = new Json_Data();
opt_code.setName(jsonobject.optString("name"));
opt_code.setId(jsonobject.optString("ID"));
json_data.add(opt_code);
datalist.add(jsonobject.optString("name"));
oprList.add(jsonobject.getString("ID"));
}
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void args) {
final Spinner mySpinner = (Spinner)getView().findViewById(R.id.operator_spinner);
mySpinner
.setAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_dropdown_item,
datalist));
mySpinner
.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0,
View arg1, int position, long arg3) {
// get Operaotor cod in opt_code field
String opt_code = oprList.get(position);
String selectedItem = arg0.getItemAtPosition(position).toString();
Log.d("Selected operator is==", "======>" + selectedItem);
Log.d("Selected Value is======", "========>" + position);
Log.d("Selected ID is======", "========>" + opt_code);
if(opt_code=="8" || opt_code=="14"|| opt_code=="35"||opt_code=="36"||opt_code=="41"||opt_code=="43")
{
_RadioGroup = (RadioGroup)getView().findViewById(R.id.radioGroup);
_RadioGroup.setVisibility(View.VISIBLE);
mySpinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int selectedId = _RadioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
RadioButton _RadioSex = (RadioButton)getView().findViewById(selectedId);
Toast.makeText(getActivity(),
_RadioSex.getText(), Toast.LENGTH_SHORT).show();
}
});
}
String user1 = myOpt.setOperator(opt_code);
String opt_name = myOpt.setOpt_provider(selectedItem);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
Image like:
Please help me, thanks.
Chenge xml like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Spinner
android:id="#+id/operator_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="7dp"
android:gravity="left"
android:textAlignment="center" >
</Spinner>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingLeft="38dp"
android:visibility="gone" >
<RadioButton
android:id="#+id/_TopUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TopUp " />
<RadioButton
android:id="#+id/Special"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Special(2G,3G,SMS,VOICE )" />
</RadioGroup>
</LinearLayout>
I've a strange problem with my custom spinner. My implementation is to hide the spinner and only fire the choices whenever i click a button so my spinner visibility is set to INVISIBLE and only fire a list of choices and assign the selected value back to a TextView. My code works only in emulator but when i went to my actual device the list of choices is not opened and only the default value is selected back to my textview. I've tried to set spinner visibility to Visible. This time i got the choices. I remember i have another implementation with the visibility is set to INVISIBLE and it worked as desired. Any clues?
XML Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EEE8E0"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:weightSum="100" >
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#E69100" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="100"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#ffffff"
android:orientation="horizontal" >
<ImageView
android:id="#+id/attach4"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:scaleType="fitXY"
android:src="#drawable/attach" />
<ImageView
android:id="#+id/attach3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:scaleType="fitXY"
android:src="#drawable/attach" />
<ImageView
android:id="#+id/attach2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_weight="1"
android:clickable="true"
android:scaleType="fitXY"
android:src="#drawable/attach" />
<ImageView
android:id="#+id/attach1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:scaleType="fitXY"
android:src="#drawable/attach" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_centerInParent="true"
android:background="#222222"
android:visibility="invisible" />
<EditText
android:id="#+id/addtitle"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/selecttype"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/edittextback"
android:gravity="right|center_vertical"
android:hint="عنوان الأعلان"
android:inputType="text"
android:lines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#444545"
android:textSize="17dp" >
</EditText>
<EditText
android:id="#+id/addbrief"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_below="#+id/addtitle"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/edittextback"
android:gravity="right|center_vertical"
android:hint="المواصفات"
android:inputType="text"
android:lines="4"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#444545"
android:textSize="17dp" />
<EditText
android:id="#+id/addprice"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_below="#+id/addbrief"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/edittextback"
android:gravity="right|center_vertical"
android:hint="السعر"
android:inputType="number"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#444545"
android:textSize="17dp" />
<Spinner
android:id="#+id/addmoney"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/addbrief"
android:layout_alignTop="#+id/addprice"
android:layout_toLeftOf="#+id/addprice"
android:background="#drawable/edittextback"
android:entries="#array/country_arrays"
android:gravity="center_horizontal|center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:prompt="#string/country_prompt"
android:textColor="#444545"
android:textSize="17dp" />
<EditText
android:id="#+id/addkilometrage"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/addprice"
android:layout_alignRight="#+id/addprice"
android:layout_below="#+id/addprice"
android:layout_marginTop="10dp"
android:background="#drawable/edittextback"
android:gravity="right|center_vertical"
android:hint="المسافة المقطوعة"
android:inputType="number"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#444545"
android:textSize="17dp" />
<Spinner
android:id="#+id/addkilo"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/addmoney"
android:layout_alignTop="#+id/addkilometrage"
android:layout_toLeftOf="#+id/addprice"
android:background="#drawable/edittextback"
android:entries="#array/kilo"
android:gravity="center_vertical|center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:prompt="#string/country_prompt"
android:textColor="#444545"
android:textSize="17dp" />
<Spinner
android:id="#+id/Spinner01"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/addkilo"
android:layout_alignRight="#+id/addkilometrage"
android:layout_below="#+id/addkilometrage"
android:layout_marginTop="10dp"
android:background="#drawable/edittextback"
android:entries="#array/year"
android:gravity="right|center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:prompt="#string/country_prompt"
android:textColor="#444545"
android:textSize="17dp" />
<EditText
android:id="#+id/EditText01"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignLeft="#+id/Spinner01"
android:layout_alignRight="#+id/Spinner01"
android:layout_below="#+id/Spinner01"
android:layout_marginTop="10dp"
android:background="#drawable/edittextback"
android:ems="10"
android:gravity="right|center_vertical"
android:hint="رقم الهاتف/الجوال"
android:inputType="number"
android:lines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#444545"
android:textSize="17dp" />
<Button
android:id="#+id/continueregist"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignLeft="#+id/EditText01"
android:layout_alignRight="#+id/addprice"
android:layout_below="#+id/EditText01"
android:layout_marginTop="26dp"
android:background="#drawable/green_buttons"
android:text="Continue"
android:textColor="#ffffff"
android:textSize="19dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:visibility="invisible" />
<Spinner
android:id="#+id/spinner_model"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:visibility="invisible" />
<ImageView
android:id="#+id/selecttype"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/addtitle"
android:layout_marginTop="20dp"
android:scaleType="fitXY"
android:src="#drawable/sell" />
<TextView
android:id="#+id/textcattype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/spinner_type"
android:layout_marginRight="21dp"
android:layout_toLeftOf="#+id/selecttype"
android:text=""
android:textSize="19dp" />
<ImageView
android:id="#+id/selectmodel"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignRight="#+id/addmoney"
android:layout_alignTop="#+id/selecttype"
android:scaleType="fitXY"
android:src="#drawable/buy" />
<TextView
android:id="#+id/textcarmodel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/selectmodel"
android:layout_toLeftOf="#+id/selectmodel"
android:text=""
android:textSize="19dp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/mainaddshekh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#222222"
android:orientation="vertical" >
</RelativeLayout>
Java Class:
public class Sell_Class extends Activity implements OnClickListener {
Spinner Type, Model;
MyAdapter adapter1;
MyAdapter2 adapter2;
EditText cartypeedit;
ImageView cartype, carmodel;
TextView cartypetext, carmodeltext;
String CarType="",CarModel;
int arr_images[] = {
R.drawable.hy,
R.drawable.hy
};
final String[] CarsType = new String[] {
"هيونداي", "هوندا",
};
final String[] Hyundai = new String[] {
"أكسنت", "أكسيل"
};
final String[] Honda = new String[] {
"أكورد", "سيفيك",
};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mainsell);
Type = (Spinner) findViewById(R.id.spinner_type);
Model = (Spinner) findViewById(R.id.spinner_model);
cartype = (ImageView) findViewById(R.id.selecttype);
carmodel = (ImageView) findViewById(R.id.selectmodel);
cartypetext = (TextView) findViewById(R.id.textcattype);
carmodeltext = (TextView) findViewById(R.id.textcarmodel);
cartype.setOnClickListener(this);
carmodel.setOnClickListener(this);
Type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// get spinner value
cartypetext.setText(CarsType[arg2]);
CarType = CarsType[arg2];
CarModel="";
carmodeltext.setText("");
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
Model.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if (CarType.contentEquals("هيونداي")) {
carmodeltext.setText(Hyundai[arg2]);
CarModel = Hyundai[arg2];
}
if (CarType.contentEquals("هوندا")) {
carmodeltext.setText(Honda[arg2]);
CarModel = Honda[arg2];
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.selecttype:
adapter1 = new MyAdapter(this, CarsType, arr_images);
Type.setAdapter(adapter1);
Type.performClick();
cartypetext.setText("");
break;
case R.id.selectmodel:
if (CarType.contentEquals("")) {
Toast.makeText(getApplicationContext(),
"Please select car first", Toast.LENGTH_LONG).show();
}
else
{
if (CarType.contentEquals("هيونداي")) {
adapter2 = new MyAdapter2(Sell_Class.this, Hyundai);
Model.setAdapter(adapter2);
Model.performClick();
carmodeltext.setText("");
}
if (CarType.contentEquals("هوندا")) {
adapter2 = new MyAdapter2(Sell_Class.this, Honda);
Model.setAdapter(adapter2);
Model.performClick();
carmodeltext.setText("");
}
}
break;
}
}
}
MyAdapter:
public class MyAdapter extends BaseAdapter {
Context c;
String[] title;
int[] pic;
LayoutInflater inflater;
Typeface font;
int arr_images[] = {
R.drawable.hy,
R.drawable.hy
};
public MyAdapter(Context context, String[] title, int[] pic) {
super();
this.c = context;
this.title = title;
this.pic = pic;
inflater = LayoutInflater.from(context);
// font = Typeface.createFromAsset(context.getAssets(),"fonts/khalaadsara.ttf");
}
#Override
public int getCount() {
return title.length;
}
public class ViewHolder {
TextView cat;
ImageView icon;
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView== null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.spinnertext, null);
holder.cat = (TextView) convertView.findViewById(R.id.titlesub);
holder.icon = (ImageView) convertView.findViewById(R.id.imageView1);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
holder.cat.setText(title[position]);
// holder.cat.setTypeface(font);
holder.icon.setImageResource(arr_images[position]);
return convertView;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
}
I am using ListView inside the row of another ListView. In wishlist.xml, I have one ListView. That items were in wishlist_items.xml, In that wishlist_items also having one more listView. that was designed in wishlist_items_advisors.xml. My problem is that send ListView is showing only one item. Can any one tell me how to fix this?
And the adapters also given below.
wishlist.xml
<LinearLayout
android:id="#+id/logo_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:contentDescription="#string/app_name" />
<LinearLayout
android:id="#+id/title_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/titleredbg"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/wishlist_title"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<Button
android:id="#+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
<Button
android:id="#+id/add_person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name"
android:padding="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_name_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:text="#string/wishlist_name"
android:textColor="#color/Black" />
<TextView
android:id="#+id/wishlist_email_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:text="#string/wishlist_email"
android:textColor="#color/Black" />
</LinearLayout>
<TextView
android:id="#+id/wishlist_relation_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="43"
android:text="#string/wishlist_relation"
android:textColor="#color/Black" />
</LinearLayout>
<LinearLayout
android:id="#+id/items_footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:weightSum="100" >
<ListView
android:id="#+id/listView_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="4dp"
android:visibility="visible" >
</ListView>
<LinearLayout
android:id="#+id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/no_data"
android:textColor="#000" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
wishlist_items.xml
<TextView
android:id="#+id/hr1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#D2D2D2" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:ellipsize="end"
android:maxLines="2"
android:text="John John John John John John"
android:textColor="#color/Black" />
<TextView
android:id="#+id/wishlist_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="krishna.mondeddu#gmail.com krishna.mondeddu#gmail.com"
android:textColor="#color/Black" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="43"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_relation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="Birthday Birthday vv Birthday Birthday"
android:textColor="#color/Black" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="40" >
<ImageButton
android:id="#+id/editButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/deleteButton"
android:background="#drawable/wishlistediticon"
android:contentDescription="#string/app_name" />
<ImageButton
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/hr4"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<TextView
android:id="#+id/gift_advisor_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/wishlist_getadvisor"
android:textColor="#color/Black" />
</LinearLayout>
<TextView
android:id="#+id/hr1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<ListView android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
></ListView>
<TextView
android:id="#+id/hr5"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#fff"
android:paddingTop="5dp"
android:paddingBottom="5dp"
>
<ImageButton
android:id="#+id/invite_advisor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
wishlist_items_advisors.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/advisor_name_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:ellipsize="end"
android:maxLines="2"
android:text="John John"
android:textColor="#color/Black" />
<TextView
android:id="#+id/advisor_email_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="krishna."
android:textColor="#color/Black" />
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="43" >
<TextView
android:id="#+id/status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/deleteButton"
android:text="Accept" />
<ImageButton
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
CustomAdapter
public class CustomAdapter extends BaseAdapter{
private String guestIds[]=null;
private String names[]=null;
private String emails[] = null;
private String relationships[] = null;
private String occasions[] = null;
DisplayImageOptions doption=null;
private ImageLoadingListener animateFirstListener =null;
private Context context=null;
public CustomAdapter(Activity activity,String[] guestId,String[] name,String[] email,String[] relationship, String[] occasion)
{
this.context=activity;
this.guestIds = guestId;
this.names =name;
this.emails = email;
this.relationships = relationship;
this.occasions = occasion;
doption=new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty).showImageOnFail(R.drawable.ic_error).showStubImage(R.drawable.ic_stub).cacheInMemory(true).cacheOnDisc(true).displayer(new RoundedBitmapDisplayer(5)).build();
animateFirstListener = new AnimateFirstDisplayListener();
}
#Override
public int getViewTypeCount() {
return 2;
}
#Override
public int getItemViewType(int position) {
//CustomAdapter item = (CustomAdapter) getItem(position);
if (isItemAnAd(position)) {
return 0;
} else {
return 1;
}
}
private boolean isItemAnAd(int position) {
// Place an ad at the first
return (position == 0);
}
#Override
public Object getItem(int arg0) {
return arg0;
}
#Override
public long getItemId(int arg0) {
return arg0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
if (convertView == null) {
view = ((Activity) context).getLayoutInflater().inflate(R.layout.wishlist_items, parent, false);
holder = new ViewHolder();
holder.wishlistName = (TextView) view.findViewById(R.id.wishlist_name);
holder.wishlistEmail = (TextView) view.findViewById(R.id.wishlist_email);
holder.wishlistRelation = (TextView) view.findViewById(R.id.wishlist_relation);
holder.wishGiftAdvisorText = (TextView) view.findViewById(R.id.gift_advisor_text);
holder.advisorListview = (ListView) view.findViewById(R.id.listView);
holder.inviteAdvisor = (ImageButton) view.findViewById(R.id.invite_advisor);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.wishlistName.setText(names[position]);
holder.wishlistEmail.setText(emails[position]);
holder.wishlistRelation.setText(relationships[position]);
holder.wishGiftAdvisorText.setText(getResources().getString( R.string.wishlist_getadvisor)+" "+names[position]+"'s "+getResources().getString( R.string.wishlist_title) );
GuestId = guestIds[position];
holder.wishlistName.setTypeface(tf);
holder.wishlistEmail.setTypeface(tf);
holder.wishlistRelation.setTypeface(tf);
holder.wishGiftAdvisorText.setTypeface(tf);
if(occasions[position].contains("[")) {
try {
array = new JSONArray(occasions[position]);
System.out.println(array.toString(2));
//loadOccasionData(array);
// TODO Auto-generated method stub
if(array!= null) {
advisorIds = new String[array.length()];
advisorNames = new String[array.length()];
advisorEmails = new String[array.length()];
advisorRelationships = new String[array.length()];
advisorStatuses = new String[array.length()];
for (int i = 0; i < array.length(); i++) {
JSONObject c;
try {
c = array.getJSONObject(i);
// Storing each json item in variable
advisorIds[i] = c.getString("advisor_id");
advisorNames[i] = c.getString("name");
advisorEmails[i] = c.getString("email");
advisorRelationships[i] = c.getString("relationship");
advisorStatuses[i] = c.getString("status");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
CustomAdvisorAdapter adapter = new CustomAdvisorAdapter(WishList.this,
advisorIds, advisorNames, advisorEmails, advisorRelationships , advisorStatuses);
holder.advisorListview.setAdapter(adapter);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
holder.advisorListview.setAdapter(null);
}
return view;
}
private class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
private class ViewHolder {
public TextView wishlistName;
public TextView wishlistEmail;
public TextView wishlistRelation;
public TextView wishGiftAdvisorText;
public ListView advisorListview;
public ImageButton inviteAdvisor;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
}
CustomAdvisorAdapter
public class CustomAdvisorAdapter extends BaseAdapter{
private String advisorIds[]=null;
private String advisorNames[]=null;
private String advisorEmails[] = null;
private String advisorRelationships[] = null;
private String advisorStatuses[] = null;
DisplayImageOptions doption=null;
private ImageLoadingListener animateFirstListener =null;
private Context context=null;
public CustomAdvisorAdapter(Activity activity,String[] advisorId,String[] advisorName,String[] advisorEmail,String[] advisorRelationship, String[] advisorStatus)
{
this.context=activity;
this.advisorIds = advisorId;
this.advisorNames =advisorName;
this.advisorEmails = advisorEmail;
this.advisorRelationships = advisorRelationship;
this.advisorStatuses = advisorStatus;
doption=new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty).showImageOnFail(R.drawable.ic_error).showStubImage(R.drawable.ic_stub).cacheInMemory(true).cacheOnDisc(true).displayer(new RoundedBitmapDisplayer(5)).build();
animateFirstListener = new AnimateFirstDisplayListener();
}
#Override
public Object getItem(int arg0) {
return arg0;
}
#Override
public long getItemId(int arg0) {
return arg0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View viewAdvisor = convertView;
final ViewHolder advisorHolder;
if (convertView == null) {
viewAdvisor = ((Activity) context).getLayoutInflater().inflate(R.layout.wishlist_items_advisor, parent, false);
advisorHolder = new ViewHolder();
advisorHolder.advisorNameText = (TextView) viewAdvisor.findViewById(R.id.advisor_name_text);
advisorHolder.advisorEmailText = (TextView) viewAdvisor.findViewById(R.id.advisor_email_text);
advisorHolder.statusText = (TextView) viewAdvisor.findViewById(R.id.status_text);
viewAdvisor.setTag(advisorHolder);
} else {
advisorHolder = (ViewHolder) viewAdvisor.getTag();
}
advisorHolder.advisorNameText.setText(advisorNames[position]);
advisorHolder.advisorEmailText.setText(advisorEmails[position]);
advisorHolder.statusText.setText(advisorStatuses[position]);
advisorHolder.advisorNameText.setTypeface(tf);
advisorHolder.advisorEmailText.setTypeface(tf);
advisorHolder.statusText.setTypeface(tf);
return viewAdvisor;
}
private class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
private class ViewHolder {
public TextView advisorNameText;
public TextView advisorEmailText;
public TextView statusText;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
}
It's not possible to make a scrollable view inside a scrollable view. But as a work around this, and only in case that this listviews doesn't take much memory if all views are loaded.
you can use this
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
public class NonScrollableListView extends ListView {
public NonScrollableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Do not use the highest two bits of Integer.MAX_VALUE because they are
// reserved for the MeasureSpec mode
int heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightSpec);
getLayoutParams().height = getMeasuredHeight();
}
}
Again, it's not good to use this workaround
you will use this non Scrollable listview in the child.xml layout by adding it as a customized UI component
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.youpackage.uiutils.NonScrollableListView
android:id="#+id/non_scrollable_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
You can ExpandableListView in place of making custom view also for data handling you can use ExpandableListAdapter.