I have a viewroom.java class to list all room names from a database as follows:
package com.iwantnew.www; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.http.NameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.annotation.TargetApi; import android.app.ListActivity; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.StrictMode; //import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; @TargetApi(Build.VERSION_CODES.GINGERBREAD) public class viewroom extends ListActivity { // url to make request private static String url = "http://10.0.2.2/iWant/src/android_view_all_room.php"; // JSON Node names private static final String TAG_ROOM = "room"; // private static final String TAG_SUCCESS = "success"; private static final String TAG_ID = "id"; private static final String TAG_LOCATION = "location"; private static final String TAG_TITLE = "title"; private static final String TAG_QUANTITY = "quantity"; private static final String TAG_PRICE = "price"; private static final String TAG_CONTACT = "contact"; private static final String TAG_AREA = "area"; private static final String TAG_DESCRIPTION = "description"; private static final String TAG_ADDRESS = "address"; // contacts JSONArray JSONArray room = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_room); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } // Hashmap for ListView ArrayList<HashMap<String, String>> roomList = new ArrayList<HashMap<String, String>>(); // Creating JSON Parser instance JSONParser jParser = new JSONParser(); List<NameValuePair> params = new ArrayList<NameValuePair>(); // getting JSON string from URL JSONObject json = jParser.makeHttpRequest(url, "GET", params); try { // Getting Array of Contacts room = json.getJSONArray(TAG_ROOM); // looping through All Contacts for(int i = 0; i < room.length(); i++){ JSONObject c = room.getJSONObject(i); // Storing each json item in variable String id = c.getString(TAG_ID); String location = c.getString(TAG_LOCATION); String quantity = c.getString(TAG_QUANTITY); String address = c.getString(TAG_ADDRESS); String price = c.getString(TAG_PRICE); String contact = c.getString(TAG_CONTACT); String area = c.getString(TAG_AREA); String description = c.getString(TAG_DESCRIPTION); String title = c.getString(TAG_TITLE); // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); // adding each child node to HashMap key => value map.put(TAG_ID, id); map.put(TAG_LOCATION, location); map.put(TAG_QUANTITY, quantity); map.put(TAG_ADDRESS, address); map.put(TAG_PRICE, price); map.put(TAG_CONTACT, contact); map.put(TAG_AREA, area); map.put(TAG_DESCRIPTION, description); map.put(TAG_TITLE, title); // adding HashList to ArrayList roomList.add(map); } } catch (JSONException e) { e.printStackTrace(); } /** * Updating parsed JSON data into ListView * */ ListAdapter adapter = new SimpleAdapter(this, roomList, R.layout.list_room, new String[] { TAG_TITLE, TAG_LOCATION, TAG_PRICE }, new int[] { R.id.title, R.id.location, R.id.price }); setListAdapter(adapter); // selecting single ListView item ListView lv = getListView(); // Launching new screen on Selecting Single ListItem lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // getting values from selected ListItem String title = ((TextView) view.findViewById(R.id.title)).getText().toString(); String location = ((TextView) view.findViewById(R.id.location)).getText().toString(); String price = ((TextView) view.findViewById(R.id.price)).getText().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), SingleRoomActivity.class); in.putExtra(TAG_TITLE, title); in.putExtra(TAG_LOCATION, location); in.putExtra(TAG_PRICE, price); startActivity(in); } }); } }
when one of these list items is clicked, the details are displayed in the room class class. It looks like this:
package com.iwantnew.www; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class SingleRoomActivity extends Activity { private static final String TAG_TITLE = "title"; private static final String TAG_LOCATION = "location"; private static final String TAG_PRICE = "price"; @Override protected void onCreate(Bundle savedInstanceState) {
there is still a large gap between each element in the classβs activity class when all data is displayed in single-room mode.
and when the list adapter is changed to
ListAdapter adapter = new SimpleAdapter(this, roomList, R.layout.list_room, new String[] { TAG_TITLE }, new int[] { R.id.title });
In view of the activity in the room, the gap disappears, but the activity in one issue does not show the entire description.
if you need my xml files: view_room.xml
<?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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" > <Button android:id="@+id/searchBtn" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@+id/slogan" android:text="@string/Search" /> <EditText android:id="@+id/searchArea" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignTop="@+id/searchBtn" android:ems="10" android:hint="@string/hint" android:inputType="text" > <requestFocus /> </EditText> <TextView android:id="@+id/slogan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/searchArea" android:layout_below="@+id/brand" android:text="@string/slogan" android:textAppearance="?android:attr/textAppearanceMedium" android:textStyle="italic" android:typeface="normal" /> <TextView android:id="@+id/brand" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/iWant" android:textSize="@dimen/iwant" /> <Button android:id="@+id/postBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="26dp" android:text="@string/post" /> <TextView android:id="@+id/room_list_heading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/searchBtn" android:text="@string/room_list_heading" android:textAppearance="?android:attr/textAppearanceMedium" android:textStyle="italic" android:typeface="normal" /> <ListView android:id="@android:id/list" android:layout_below="@+id/room_list_heading" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </RelativeLayout>
single room.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/title_label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="25dip" android:textStyle="bold" android:paddingTop="10dip" android:paddingBottom="10dip" android:textColor="#43bd00"/> <TextView android:id="@+id/quantity_label" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/location_label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold"/> <TextView android:id="@+id/price_label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="25dip" android:textStyle="bold" android:paddingTop="10dip" android:paddingBottom="10dip" android:textColor="#43bd00"/> <TextView android:id="@+id/contact_label" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/description_label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold"/> <TextView android:id="@+id/area_label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="25dip" android:textStyle="bold" android:paddingTop="10dip" android:paddingBottom="10dip" android:textColor="#43bd00"/> <TextView android:id="@+id/address_label" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </LinearLayout>
list_room.xml
<?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="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#43bd00" android:textSize="16sp" android:textStyle="bold" android:paddingTop="6dip" android:paddingBottom="2dip" /> <TextView android:id="@+id/location" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip"> </TextView> <TextView android:id="@+id/quantity" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip"> </TextView> <TextView android:id="@+id/price" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip"> </TextView> <TextView android:id="@+id/contact" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip"> </TextView> <TextView android:id="@+id/area" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip"> </TextView> <TextView android:id="@+id/description" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip"> </TextView> <TextView android:id="@+id/address" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip"> </TextView> </LinearLayout>


I want to fade the gap in the first image and still get the second image as it is.