ListItem Click doesn't work - java

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

Related

TextView in listViews added inside a Fragment displaying but empty (no text)

I want to display a list of items containing 2 textview in one of my fragment. Something really simple since I'm learning how to use listviews.
Here is my code:
public class CommandeFragment extends Fragment{
private BarMenu myMenu;
View myView;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.commande_layout,container, false);
myMenu = (BarMenu) getArguments().getSerializable(MENU_KEY);
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i = 0; i < myMenu.drinks.size(); i++){
HashMap<String,String> hm = new HashMap<String, String>();
hm.put("Name",myMenu.drinks.get(i).drinkName);
hm.put("Price",myMenu.drinks.get(i).drinkPrice.toString());
aList.add(hm);
}
String[] from = {"drinkName","drinkPrice"};
int[] to = {R.id.textView3,R.id.textView4};
SimpleAdapter adapter = new SimpleAdapter(myView.getContext(), aList, R.layout.listview_commande_layout, from, to);
ListView listView = (ListView) myView.findViewById(R.id.listView);
listView.setAdapter(adapter);
return myView;
}
}
When I run this, I got a list of textviews placed correctly but the problem is that the text inside is empty. I've try multiple advice about the xml files online but I'm pretty sure it's fine.
Here it is in case:
listview_commande_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_weight="1" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
commande_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:text="Bar Menu Layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="102dp"
android:id="#+id/textView2" />
</RelativeLayout>
The column names you pass to your adapter don't match the column names in your HashMap ("Name" vs. "drinkName"). If you update these to match, it should work.
for(int i = 0; i < myMenu.drinks.size(); i++){
HashMap<String,String> hm = new HashMap<String, String>();
hm.put("Name",myMenu.drinks.get(i).drinkName);
hm.put("Price",myMenu.drinks.get(i).drinkPrice.toString());
aList.add(hm);
}
String[] from = {"Name","Price"}; //changed from {"drinkName","drinkPrice"}

Add button at end Listview android

so , i have a Listview activity , that is populated by values from a SQLITE database.
how can i put a button fixed at top or bottom ?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/coligada"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:layout_alignBottom="#+id/editar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_weight="1"/>
<Button
android:id="#+id/editar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantidadesxsx"
android:onClick="editar"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/coligada"
android:layout_toEndOf="#+id/coligada" />
</RelativeLayout>
Here is my ProductAdapter that have custom layout where have the items and a apdater that populate my listview with values from Sqlite database.
package br.exemplosqlite;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.List;
public class ProdutosAdapter extends BaseAdapter {
private Context context;
private List<Produtos> list;
public ProdutosAdapter(Context context, List<Produtos> list){
this.context = context;
this.list = list;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0).getId();
}
#Override
public View getView(int position, View arg1, ViewGroup arg2) {
final int auxPosition = position;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.produtos, null);
TextView tv = (TextView) layout.findViewById(R.id.coligada);
tv.setText(list.get(position).getItem());
Button editarBt = (Button) layout.findViewById(R.id.editar);
editarBt.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, NewUserActivity.class);
intent.putExtra("item", list.get(auxPosition).getItem());
intent.putExtra("quantidaderm",list.get(auxPosition).getQuantidaderm());
intent.putExtra("id", list.get(auxPosition).getId());
context.startActivity(intent);
}
});
// *********** BOTÃO DE EXCLUIR ***************** //
//Button deletarBt = (Button) layout.findViewById(R.id.deletar);
//deletarBt.setOnClickListener(new Button.OnClickListener(){
// #Override
// public void onClick(View arg0) {
// BD bd = new BD(context);
// bd.deletar(list.get(auxPosition));
//
// layout.setVisibility(View.GONE);
// }
//}
///);
return layout;
}
}
Try the following xml at the bottom of ListView and centerHorizontal
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Your Button"
/>
</RelativeLayout>
Hope this helps.
Do it like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Your text here"/>
</LinearLayout>
Try 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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.05"
android:orientation="horizontal" >
<TextView
android:id="#+id/coligada"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_weight="1"
android:text="Large Text" />
<Button
android:id="#+id/editar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/coligada"
android:layout_toRightOf="#+id/coligada"
android:onClick="editar"
android:text="Quantidadesxsx" />
</LinearLayout>
</LinearLayout>
Try this.
<Button
android:id="#+id/btn"
layout_width="wrap_content"
layout_height="wrap_content"
android:alignParentTop="true"
/>
<ListView
layout_width="wrap_content"
layout_height="wrap_content"
android:layout_below="#+id/btn"
/>
Current layout is for listview items.
Remove Button from this layout file and paste it in layout file where you have defined ListView.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<ListView
.....
</ListView>
<Button>
</Button>
</RelativeLayout>
in one layout and
<TextView>
</TextView>
in another layout
In button add this line of code
<Button
android:id="#+id/editar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantidadesxsx"
android:onClick="editar"
android:layout_below="#+id/coligada"/>
You can use android:layout_weight="1" with LinearLayout.
Example.
<?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/txtView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/editar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantidadesxsx"
android:onClick="editar"/>
</LinearLayout>

Android - Output value of custom listview - Getting errors

Problem: Trying to output the description of the selected listview. My code is below, and I also have an example of what my listview looks like as well as the code that creates it. I have a custom listview that shows three values, when I click the 2nd line (3/12/04 Gas $60.00) I want it to output the description ("Gas").
The onItemClick is where my issue is in ItemMenuActivity.
Thanks for your help and time!
Example Data in listview:
3/12/04 New Shoes $50.00
3/12/04 Gas $60.00
3/12/04 Food $10.00
ItemMenuActivity.java
public class ItemMenuActivity extends Activity implements AdapterView.OnItemClickListener
{
String accountName;
ArrayList<Item> item_details;
DatabaseHandler database;
ListView itemView;
private EditText dateEditText, costEditText, desEditText;
private Spinner categorySpinner;
private Button btnAddItem, btnCancel;
private boolean errlvl;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.item_menu_layout);
// Initiate Database
database = new DatabaseHandler(getApplicationContext());
// Initiate/configure ListView
itemView = (ListView)findViewById(R.id.itemListView);
itemView.setOnItemClickListener(this);
Bundle bundle = getIntent().getExtras();
String account_name = bundle.getString("AccountName");
setTitle(account_name);
accountName = account_name;
displaySpecificItemListView(accountName);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
//TextView editTextDescription = ((TextView)view.findViewById(R.id.editTextDescription));
//String temp = editTextDescription.getText().toString();
//Toast.makeText(this, temp, Toast.LENGTH_LONG).show();
}
}
add_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/addItemLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="#string/purchDateTitle"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<EditText
android:id="#+id/editTextDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/editTextDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:hint="Enter Item Description"
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:text="$ "
android:textSize="20dp"/>
<EditText
android:id="#+id/editTextCost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:hint="Enter Total Cost"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Spinner
android:id="#+id/categorySelectSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal">
<Button
android:id="#+id/btnAddItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Add" />
<Button
android:id="#+id/btnCancelItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
ItemListViewBaseAdapter.java
public class ItemListViewBaseAdapter extends BaseAdapter
{
private ArrayList<Item> _data;
Context _c;
ItemListViewBaseAdapter (ArrayList<Item> data, Context c)
{
_data = data;
_c = c;
}
public int getCount()
{
// TODO Auto generated method stub
return _data.size();
}
public Object getItem(int position)
{
// TODO Auto generated method stub
return _data.get(position);
}
public long getItemId(int position)
{
// TODO Auto generated method stub
return position;
}
public View getView (int position, View convertView, ViewGroup parent)
{
// TODO Auto generate method stub
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)_c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.custom_item_listview_layout, null);
}
TextView itemDate = (TextView)v.findViewById(R.id.dateTextView);
TextView itemDescription = (TextView)v.findViewById(R.id.descriptionTextView);
TextView itemAmount = (TextView)v.findViewById(R.id.amountTextView);
Item accMsg = _data.get(position);
itemDate.setText(accMsg.entry_date);
itemDescription.setText(accMsg.item_description);
//NumberFormat format
if(accMsg.item_price > 0)
{
String myString = String.format("%.2f", accMsg.item_price);
String FormattedString = "$"+myString;
itemAmount.setText(FormattedString);
}
else
{
double temp = Math.abs(accMsg.item_price);
String myString = String.format("%.2f", temp);
String FormattedString = "-$"+myString;
itemAmount.setText(FormattedString);
itemAmount.setTextColor(Color.parseColor("#088A08"));
}
return v;
}
}
item_menu_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/itemListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="0.1dp"
android:divider="#81A594"
android:layout_below="#+id/dateTitle"/>
</RelativeLayout>
In your onItemClick() method you're doing
TextView editTextDescription = ((TextView)view.findViewById(R.id.editTextDescription));
to get your TextView. This matches the XML you posted (add_item_layout.xml), but your adapter code tells a different story.
In your adapter, for new rows you are inflating custom_item_listview_layout and your "description" TextView ID is R.id.descriptionTextView.
So if you make this edit in onItemClick(), it should solve your problem:
TextView editTextDescription = ((TextView)view.findViewById(R.id.descriptionTextView));

Tabs doesn't take full width of the screen

I am creating tabs inside the fragment class. Right now i am showing two tabs in the fragment class. Everything works fine and tabs are shown properly. Only cache is that, the tabs shown only take half of the screen width, It doesn't take the full screen width.
So anyone tell me what i need to change in my code to achieve that
My Code
tabsinfo_fragment.xml file
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EFEFEF" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/tab_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<FrameLayout
android:id="#+id/tab_2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
</TabHost>
tab.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp"
android:background="#drawable/tab_selector">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#drawable/tab_text_selector"
android:textIsSelectable="false" />
</LinearLayout>
code inside fragment class
public class TabsInfoFragment extends Fragment implements OnTabChangeListener
{
private View m_Root;
private TabHost m_TabHost;
private int m_CurrentTab;
public String m_VisitorTabText;
public String m_FeedTabText;
public TabsInfoFragment()
{
}
#Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
m_VisitorTabText = Integer.toString(R.string.tab_visitor_text);
m_FeedTabText = Integer.toString(R.string.tab_feed_text);
m_Root = inflater.inflate(R.layout.tabsinfo_fragment, null);
m_TabHost = (TabHost) m_Root.findViewById(android.R.id.tabhost);
setupTabs();
return m_Root;
}
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
setRetainInstance(true);
m_TabHost.setOnTabChangedListener(this);
m_TabHost.setCurrentTab(m_CurrentTab);
// Manually start loading stuff in the first tab
updateTab(m_VisitorTabText, R.id.tab_1, new ProfileInfoFragment());
}
private void setupTabs()
{
m_TabHost.setup();
m_TabHost.addTab(newTab(m_VisitorTabText, R.string.tab_visitor_text, R.id.tab_1));
m_TabHost.addTab(newTab(m_FeedTabText, R.string.tab_feed_text, R.id.tab_2));
}
private TabSpec newTab(String tag, int labelId, int tabContentId)
{
View indicator = LayoutInflater.from(getActivity()).inflate(R.layout.tab, (ViewGroup) m_Root.findViewById(android.R.id.tabs), false);
((TextView) indicator.findViewById(R.id.text)).setText(labelId);
TabSpec tabSpec = m_TabHost.newTabSpec(tag);
tabSpec.setIndicator(indicator);
tabSpec.setContent(tabContentId);
return tabSpec;
}
#Override
public void onTabChanged(String tabId)
{
if (m_VisitorTabText.equals(tabId))
{
updateTab(tabId, R.id.tab_1, new ProfileInfoFragment());
m_CurrentTab = 0;
return;
}
if (m_FeedTabText.equals(tabId))
{
updateTab(tabId, R.id.tab_2, new ProfileInfoFragment());
m_CurrentTab = 1;
return;
}
}
private void updateTab(String tabId, int placeholder, Fragment fragmentClass)
{
FragmentManager fm = getFragmentManager();
if (fm.findFragmentByTag(tabId) == null)
{
fm.beginTransaction().replace(placeholder, fragmentClass, tabId).commit();
}
}
}
ScreenShot
The TabWidget class is a subclass of LinearLayout, so in the tab.xml file for the root xml element, in your case a LinearLayout, set the width to 0dp and the weight to 1, then all the tabs will be equal width. Like so:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:gravity="center">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="This is a tab" />
</LinearLayout>
Try changing your TabWidget to this instead;
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
try this
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="#+android:id/tab_1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<FrameLayout
android:id="#+android:id/tab_2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
Try removing HorizontalScrollView and adding android:layout_width="fill_parent" to TabWidget
Need to add one single line
tabs.setDistributeEvenly(true);

android customized listview via soap calling

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>

Categories