i have try to retrieve data from mysql database via soap calling.
Here am facing following problem.
i have used below webservice code:
public class RetailerWs {
public String customerData1(){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
//Find customer information where the customer ID is maximum
PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_orders");
ResultSet result = statement.executeQuery();
while(result.next()){
customerInfo = customerInfo
+ result.getString("orderid")
+ " " // this to separate order id from status
+ result.getString("status")
+ " "
+ result.getString("payment_method")
+ " "
+ result.getString("total")
+ " "
// this to separate order id from status
+ result.getString("login")
+ "&" ;
}}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return customerInfo;
}}
This is my android code:
public class RetailerActivity extends Activity {
ListView list;
private static final String SOAP_ACTION = "http://xcart.com/customerData1";
private static final String METHOD_NAME = "customerData1";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://192.168.1.168:8089/XcartLogin/services/RetailerWs?wsdl";
private static final String KEY_STATUS = "status";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");
list=(ListView)findViewById(R.id.list);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
//R.layout.list_row, R.id.orderid);
list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,resultArr));
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String s2= getIntent().getStringExtra("status");
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_STATUS, s2);
startActivity(in);
}
});
}
catch (Exception e) {
e.printStackTrace();
}
}
}
This is my current o/p:
But i wish to need the o/p like below format:
1 P 399.99
Krishna
Check(manual processing)
------------------------------
2 P 314.65
Krishna
Phone Ordering
------------------------------
please help me ..how can i develop this.
You can Do this by creating 2 xml
First xml would be defining your hearder of List View and your Data to be filled in List
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#EFEFF7"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="ID" android:width="120dip" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
android:height="25sp" />
<TextView android:text="Name" android:layout_weight="1.0" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
android:height="25sp" />
<TextView android:text="Money ($)" android:width="80dip" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
android:height="25sp" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#000000" android:height="1sp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:height="1sp" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000000">
<ListView android:id="#+id/android:list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1.0" />
</LinearLayout>
</LinearLayout>
and ListView which is First xml can be define in other other xml which item you need in ListView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/lv"
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#000000">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000000">
<TextView android:id="#+id/ID" android:textColor="#FFFFFF" android:typeface="sans"
android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
android:width="120dip" /> //Can use this ID to display ID for Example 1
<TextView android:id="#+id/Name" android:textColor="#FFFFFF" android:typeface="sans"
android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
android:layout_weight="1.0" /> //Can use this ID to display Name Like P
<TextView android:id="#+id/Money" android:textColor="#FFFFFF" android:typeface="sans"
android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
android:width="80dip" /> //Can use this ID to display Money like 300 $
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#EFEFF7">
<TextView android:textSize="20sp" android:text="Namee of person " android:textColor="#000000" android:typeface="sans"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:width="90dip" /> // you display krishna through this ID
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#EFEFF7">
<TextView android:textSize="20sp" android:text="Namee of person " android:textColor="#000000" android:typeface="sans"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:width="90dip" /> // you display phone ordering through this ID
</LinearLayout>
</LinearLayout>
Related
I'm just trying to add spinners dynamicallyand I found my way here Add Spinner dynamically in a loop
that works good but my issue is the view takes place instead of my original layout (a header, a footer and an image view).
I would like to place it in a specific layout in the xml file, between the header and the footer for example.
Is there a way to do this?
my code
protected void onCreate(Bundle savedInstanceState) {
Intent i = getIntent();
conteneur = "container No : " + i.getStringExtra("container");
conteneur_s = i.getStringExtra("container");
fichano = i.getStringExtra("fichano");
pos = i.getIntExtra("pos", 0);
latitude = i.getDoubleExtra("geolat", 0);
longitude = i.getDoubleExtra("geolon", 0);
volume = i.getStringExtra("volume");
saver = i.getStringExtra("saver");
poids = i.getStringExtra("poids");
tel = i.getStringExtra("telpass");
driver = i.getStringExtra("driverpass");
tour = i.getStringExtra("tour");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_parc);
container = (TextView) findViewById(R.id.nom);
container.setText(conteneur);
RelativeLayout lr = (RelativeLayout) findViewById(R.id.full_layout);
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[] {0xFFFFFFFF,0xFFB0B0B0});
gd.setCornerRadius(0f);
lr.setBackground(gd);
showImg = (ImageView) findViewById(R.id.imageView1);
String pathparc = Environment.getExternalStorageDirectory() + "/SmartCollecte/PARC/PARAM";
File f = new File(pathparc);
final File file[] = f.listFiles();
LinearLayout layout = new LinearLayout(MAIN_parcActivity.this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(140, 398);
layoutParams.setMargins(24, 50, 24, 0);
layout.setOrientation(LinearLayout.VERTICAL);
for (int j = 0; j < file.length; j++) {
String[] namewext;
namewext = FilenameUtils.removeExtension(file[j].getName()).split("_");
Toast.makeText(getApplicationContext(),namewext[1],Toast.LENGTH_SHORT).show();
Spinner spinner = new Spinner(getApplicationContext());
String[]choix = new String[]{"choisissez"+j, "Propreté", "Détérioration", "Accès", "Maintenance", "autre"};
List<String> str = new ArrayList<>();
str.add(namewext[1]);
Collections.addAll(str,choix);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MAIN_parcActivity.this,
android.R.layout.simple_spinner_item, str);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
layout.addView(spinner);
setContentView(layout,layoutParams);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/full_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#909090"
>
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:orientation="horizontal"
android:background="#E25D63"
android:layout_alignParentTop="true"
android:weightSum="3">
<ImageView
android:layout_width="60sp"
android:layout_height="60sp"
android:gravity="left"
android:src="#drawable/backinblack"
android:background="#CFCFCF"
android:layout_weight="0.20"
android:onClick="fermer"
/>
<TextView
android:id="#+id/nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#220c0c"
android:text="Tournée"
android:textStyle="bold"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:layout_weight="0.80"
android:background="#E25D63"
android:layout_gravity="center_vertical"
>
</TextView>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/anom_ctn"
android:layout_weight="0.20"
android:background="#CFCFCF"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scroll"
android:layout_below="#+id/header"
android:layout_above="#+id/footer"
android:fillViewport="true">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "#+id/spin"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:gravity="center_horizontal"
android:text="Etat de parc"
android:textSize="25sp"
android:layout_marginBottom="5dp"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "#+id/spin2"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/spin">
<Spinner
android:id="#+id/gametime"
android:layout_marginTop="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/anomalie"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/boutons"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/spin2">
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_below="#id/boutons"
android:layout_margin="40sp"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:layout_height="fill_parent"
android:layout_width="wrap_content"></ImageView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:orientation="horizontal"
android:background="#cfcfcf"
android:weightSum="3"
android:layout_alignParentBottom="true"
>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/photo"
android:layout_weight="0.80"
android:paddingRight="30sp"
android:onClick="photo"
android:clickable="true"
/>
<View android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1.40"/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/validation_test"
android:layout_weight="0.80"
android:paddingTop="10sp"
android:paddingLeft="25sp"
android:onClick="enregistrer"
android:clickable="true"
/>
</LinearLayout>
I'm not terribly sure here, I wonder if it is replacing the view because you aren't setting a unique ID for each view? That or failing to call layout.invalidate() after finishing a run through the loop.
Very little experience when it comes to Java. My app pulls data from an API to a list view just fine. Once clicked on the list view I want to display more details. My code is in different files and I can't figure out how handle null results when I set my text view text. Right now it is giving me a few errors. Thank you in advanced. I've tried debugging and my own research to no avail for over a day.
My error was: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference.
MainActivity.java:
public void showMemberDetailsScreen(int _id) {
mMembersListScreen.setVisibility(View.GONE);
mMemberDetailsScreen.setVisibility(View.VISIBLE);
if (NetworkUtils.isConnected(this)) {
GetDetailsTask task = new GetDetailsTask(this);
task.execute(_id);
} else {
Log.i(TAG, "onCreate: NOT CONNECTED");
}
}
/**
* Populate the member details screen with data.
*
* #param _name
* #param _birthday
* #param _gender
* #param _twitterId
* #param _numCommittees
* #param _numRoles
*/
public void populateMemberDetailsScreen(String _name, String _birthday, String _gender,
String _twitterId, String _numCommittees, String _numRoles) {
TextView tv = (TextView)mMembersListScreen.findViewById(R.id.text_name);
tv.setText(_name);
tv = (TextView)mMembersListScreen.findViewById(R.id.text_birthday);
tv.setText(_birthday);
tv = (TextView)mMembersListScreen.findViewById(R.id.text_gender);
tv.setText(_gender);
tv = (TextView)mMembersListScreen.findViewById(R.id.text_twitter_id);
tv.setText(_twitterId);
tv = (TextView)mMembersListScreen.findViewById(R.id.text_num_committees);
tv.setText(_numCommittees);
tv = (TextView)mMembersListScreen.findViewById(R.id.text_num_roles);
tv.setText(_numRoles);
}
OnItemClickListener mItemClickListener = new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> _parent, View _view, int _position, long _id) {
// TODO: Show the members detail screen
Log.i(TAG, "onItemClick: RAN");
showMemberDetailsScreen(_position);
Log.i(TAG, "onItemClick: POSITION = " + _position);
}
};
GetDetailsTask.java:
private static final String NAME = "name";
private static final String BIRTHDAY = "birthday";
private static final String GENDER = "gender";
private static final String TWITTER_ID = "twitter_id";
private static final String NUM_COMMITTEES = "num_committees";
private static final String NUM_ROLES = "num_roles";
private MainActivity mActivity;
public GetDetailsTask(MainActivity _activity) {
mActivity = _activity;
}
#Override
protected HashMap<String, String> doInBackground(Integer... _params) {
// Add member ID to the end of the URL
String data = NetworkUtils.getNetworkData(API_URL + _params[0]);
HashMap<String, String> retValues = new HashMap<String, String>();
try {
JSONObject response = new JSONObject(data);
String name = response.optString("name");
retValues.put(NAME, name);
String birthday = response.optString("birthday");
retValues.put(BIRTHDAY, birthday);
String gender = response.optString("gender_label");
retValues.put(GENDER, gender);
String twitterId = response.optString("twitterid");
retValues.put(TWITTER_ID, twitterId);
if (response.has("committeeassignments")) {
JSONArray committeeArray = response.optJSONArray("committeeassignments");
int numCommittees = committeeArray.length();
retValues.put(NUM_COMMITTEES, "" + numCommittees);
Log.i(TAG, "doInBackground: NUM COMMITTESS = " + numCommittees);
} else {
retValues.put(NUM_COMMITTEES, "" + 0);
}
if (response.has("roles")){
JSONArray rolesArray = response.optJSONArray("roles");
int numRoles = rolesArray.length();
retValues.put(NUM_ROLES, "" + numRoles);
} else {
retValues.put(NUM_ROLES, "" + 0);
}
} catch(JSONException e) {
e.printStackTrace();
}
return retValues;
}
#Override
protected void onPostExecute(HashMap<String, String> _result) {
super.onPostExecute(_result);
if (_result != null) {
String name = _result.get(NAME);
String birthday = _result.get(BIRTHDAY);
String gender = _result.get(GENDER);
String twitterId = _result.get(TWITTER_ID);
String numCommittees = _result.get(NUM_COMMITTEES);
String numRoles = _result.get(NUM_ROLES);
mActivity.populateMemberDetailsScreen(name, birthday, gender, twitterId, numCommittees, numRoles);
}
}
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/members_list_screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="gone" >
<ListView
android:id="#+id/members_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/member_details_screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="gone" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/name" />
<TextView
android:id="#+id/text_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/birthday" />
<TextView android:id="#+id/text_birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/gender" />
<TextView
android:id="#+id/text_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/twitter_id" />
<TextView android:id="#+id/text_twitter_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/num_committees" />
<TextView
android:id="#+id/text_num_committees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/name" />
<TextView
android:id="#+id/text_num_roles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
You are trying to show your details screen but in your method you are finding view by id under your mMembersListScreen when you should use mMemberDetailsScreen. Try this:
public void populateMemberDetailsScreen(String _name, String _birthday, String _gender,
String _twitterId, String _numCommittees, String _numRoles) {
TextView tv = (TextView) mMemberDetailsScreen.findViewById(R.id.text_name);
tv.setText(_name);
tv = (TextView) mMemberDetailsScreen.findViewById(R.id.text_birthday);
tv.setText(_birthday);
tv = (TextView) mMemberDetailsScreen.findViewById(R.id.text_gender);
tv.setText(_gender);
tv = (TextView) mMemberDetailsScreen.findViewById(R.id.text_twitter_id);
tv.setText(_twitterId);
tv = (TextView) mMemberDetailsScreen.findViewById(R.id.text_num_committees);
tv.setText(_numCommittees);
tv = (TextView) mMemberDetailsScreen.findViewById(R.id.text_num_roles);
tv.setText(_numRoles);
}
I want to show the comments on the page, created a layout:
(ListView, at the very end. At the beginning of this information about this post).
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="71dp"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<LinearLayout
android:id="#+id/lineradapter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp">
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="6dp">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:fontFamily="normal"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#525252"
android:textSize="16sp"
android:textStyle="normal" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:fontFamily="normal"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:text="00:00"
android:textColor="#999999"
android:textSize="14sp"
android:textStyle="italic" />
</FrameLayout>
<TextView
android:id="#+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="6dip"
android:textColor="#acacac"
android:textSize="16dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#e7e7e7"
android:paddingTop="6dp"
android:paddingBottom="4dp" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:layout_gravity="top|center"/>
<ListView
android:id="#+id/commentList"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
But ListView do not scroll down and just shows one element. How to make so that ListView to scroll down?
How it looks:
http://imageshack.com/a/img41/9280/3sk9.jpg
and how i fill the listview:
public class ParseComment extends AsyncTask<String, String, String> {
final String TAG = "ParseComment.java";
JSONArray dataJsonArr = null;
#Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try {
JsonParser jParser = new JsonParser();
JSONObject json = jParser.getJSONFromUrl(URL+postID);
dataJsonArr = json.getJSONArray("data");
for (int i = 0; i < 5; i++) {
JSONObject c = dataJsonArr.getJSONObject(i);
String username = "test";
String date = "1396083521";
String text = "test";
comments.add(new CommentInfo(username, text, date));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String strFromDoInBg)
{
CommentSet();
}
}
public void CommentSet()
{
commentAdapter = new CommentAdapter(this, comments);
ListView commentList = (ListView) findViewById(R.id.commentList);
commentList.setAdapter(commentAdapter);
}
In my code i want to show webview and textview in a list from Rss feed.Here is the code:
public class VediolistfetchActivity extends Activity {
/** Called when the activity is first created. */
ListView Feed;
URL url;
String[] title = { " " }, image={""};
ArrayAdapter<String> adapter;
ArrayList<Home> homes = new ArrayList<Home>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Feed = (ListView) findViewById(R.id.list);
try {
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
url = new URL("http://www.powergroupbd.com/sweethome/videolist.xml");
RSSHandler myXMLHandler = new RSSHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
ArrayList<String> GOTTitle = myXMLHandler.gotTitle();
ArrayList<String> GOTImage = myXMLHandler.gotImage();
title = new String[GOTTitle.size()];
image = new String[GOTImage.size()];
for (int i = 0; i < GOTTitle.size(); i++) {
Home home = new Home();
title[i] = GOTTitle.get(i).toString();
image[i] = GOTImage.get(i).toString();
home.openclose=GOTTitle.get(i);
home.imagehome=GOTImage.get(i);
homes.add(home);
}
HomeAdapter homeAdapter = new HomeAdapter(
VediolistfetchActivity.this, R.layout.list_catagory,
homes);
Feed.setAdapter(homeAdapter);
}
catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Something Went Wrong, Please check your net connection",
Toast.LENGTH_LONG).show();
}
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Log.i("List Click", "Yes");
String dtlHomeTitle = Feed.getItemAtPosition(arg2).toString();
Log.i("title", dtlHomeTitle);
}
}
Here is my main.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="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:divider="#000000"
android:scrollbars="none"
android:scrollingCache="true" />
</LinearLayout>
And here is listcatagory.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="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="1px"
android:layout_height="1px"
android:layout_weight="1" >
</ListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="38"
android:orientation="vertical" >
<WebView
android:id="#+id/img"
android:layout_width="70dp"
android:layout_height="70dp"
android:paddingBottom="2dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:scaleType="centerCrop"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="15"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="20dp"
android:textStyle="bold"
android:paddingLeft="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="47"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
But when i click the individual listitem nothing is happen..plz anybody tell me why this is happens?
You didn't actually set the onItemClick listener on your ListView
try this in your onCreate
Feed = (ListView) findViewById(R.id.list);
Feed.setOnItemClickListener(this);
#edit: noticed you don't actually have your class implement the OnItemClickListener despite creating a method identical to the one you'd implement. Make sure you add implements OnItemClickListener to your class declaration
public class VediolistfetchActivity extends Activity implements OnItemClickListener
I recently just overhauled my application to use ListView instead of using the classic TextView.setText and looping the inflation of a layout. I was able to acheive this very well but now I'm having a problem having it fill the screen. Heres the section of my code that does the work.
//Place JSON data into array one item at a time
JSONArray jArray = new JSONArray(result);
//Loop through each record in the database
//Get ListView
ListView lv= (ListView)findViewById(R.id.listview);
// create the grid item mapping
String[] from = new String[] {"lblQuote", "lblBuzzed", "lblShared", "lblSaid", "lblLikes", "lblHates", "lblLocation", "lblDate"};
int[] to = new int[] { R.id.lblQuote, R.id.lblBuzzed, R.id.lblShared, R.id.lblSaid, R.id.lblLikes, R.id.lblHates, R.id.lblLocation, R.id.lblDate };
for(int i=0;i<jArray.length();i++){
Log.i("uDrew Debug", "Made it into JSONArray Loop");
//Get this record
JSONObject json_data = jArray.getJSONObject(i);
//Put each result into variables for later handling
strFName = json_data.getString("FName");
strLInitial = json_data.getString("LInitial");
strCity = json_data.getString("City");
strState = json_data.getString("State");
strDate = json_data.getString("Date");
strQuote = json_data.getString("Quote");
intLikes = Integer.parseInt(json_data.getString("Likes"));
intHates = Integer.parseInt(json_data.getString("Hates"));
strFNameSaid = json_data.getString("FNameSaid");
strLInitialSaid = json_data.getString("LInitialSaid");
intBuzz = Integer.parseInt(json_data.getString("Buzz"));
Log.i("uDrew Debug", "Made it past JSON Parsing");
switch(intBuzz){
case 1:
strBuzzed = ("One Beer\nSyndrome");
break;
case 2:
strBuzzed = ("Buzzed");
break;
case 3:
strBuzzed = ("Drunk");
break;
case 4:
strBuzzed = ("Trashed");
break;
case 5:
strBuzzed = "Retarded";
break;
}
HashMap<String, String> map = new HashMap<String, String>();
map.put("lblQuote", strQuote);
map.put("lblBuzzed", strBuzzed);
map.put("lblShared", strFName + " " + strLInitial);
map.put("lblSaid",strFNameSaid + " " + strLInitialSaid);
map.put("lblDate", strDate);
map.put("lblLocation", strCity + ", " + strState);
map.put("lblLikes", intLikes.toString());
map.put("lblHates", intHates.toString());
fillMaps.add(map);
}//End For loop
// fill in the grid_item layout
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.myviews, from, to);
lv.setAdapter(adapter);
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:id="#+id/myMainLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.ads.AdView android:id="#+id/adViewer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14de539f600385"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="RandomDrunkQuotes.com"
android:id="#+id/lblTitle"
android:textSize="16px"
android:padding="5px"
android:textStyle="bold"
android:gravity="center_horizontal"/>
<!-- List Divider -->
<View android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<!-- ListView (grid_items) -->
<LinearLayout android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<ListView android:id="#+id/listview"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
</LinearLayout>
</ScrollView>
myviews.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblQuote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Filler Text"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left">
<ImageView
android:id="#+id/imgUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingLeft="5px"
android:paddingRight="5px"
android:src="#drawable/thumbsup"
android:layout_gravity="left"/>
<TextView
android:id="#+id/lblLikes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingLeft="5px"
android:paddingRight="5px"
android:textSize="4pt"
android:text="10"
android:layout_gravity="left"/>
<TextView
android:id="#+id/lblBuzzedTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textSize="4pt"
android:text="Buzz Level:"/>
<TextView
android:id="#+id/lblShared"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Shared By: Filler Name"
android:textSize="4pt"/>
<TextView
android:id="#+id/lblSaid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Said By: Filler Name"
android:textSize="4pt"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left">
<ImageView
android:id="#+id/imgDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingLeft="5px"
android:paddingRight="5px"
android:src="#drawable/thumbsdn"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/lblHates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingLeft="5px"
android:paddingRight="5px"
android:textSize="4pt"
android:text="2"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/lblBuzzed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="High"
android:textSize="4pt"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/lblDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textSize="4pt"
android:text="04/04/1987 4:32 PM"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/lblLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textSize="4pt"
android:text="Broomfield, CO"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:text=" "
android:textSize="1pt"
android:background="#6F7285"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Heres what the App looks like:
There are also no scrollbars and if I change the main.xml ScrolView layout_height="fill_parent" it extends to the end of the screen but the scrollable option isn't there.
Use android:layout_height="fill_parent" in your ScrollView and in the first LinearLayout.
Don't wrap the ListView inside a LinearLayout (the one below the divider View). There's absolutely no need for that.
(Optional) you might want to move the AdView outside the ScollView so it is always visible and not scrolled away
The following code fixed my problem:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:id="#+id/BigLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:id="#+id/myMainLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.ads.AdView android:id="#+id/adViewer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14de539f600385"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="RandomDrunkQuotes.com"
android:id="#+id/lblTitle"
android:textSize="16px"
android:padding="5px"
android:textStyle="bold"
android:gravity="center_horizontal"/>
<!-- List Divider -->
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
</LinearLayout>
<!-- ListView (grid_items) -->
<ListView
android:id="#+id/listview"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>