【发布时间】:2014-01-21 06:19:27
【问题描述】:
大家好,我在调用具有不同值的选项卡栏事件时遇到问题。因为选项卡栏视图在单个调用时加载。无法为类传递不同的值。例如,我必须加载 fri17、sat18、sun19 选项卡在标签栏类上。它的内容为第 17 天值、第 18 天值、第 19 天值。在将日期 17 传递给列表类后,必须在列表视图中加载。我尝试了更改侦听器的选项卡。仍然找不到解决这个问题的方法。谁能帮忙我。
package com.androidexample.tabbar;
import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class TabBar extends TabActivity implements OnTabChangeListener{
public static String name;
static final String URL = "http://182.160.161.2/~mani/homeshow/web_serv/timeTableGetByRequest.php?event_id=14&sortBy=time";
static final String KEY_SONG = "date"; // parent node
static final String KEY_IDs = "timetable_date";
public HashMap<String, String> map;
public ArrayList<HashMap<String, String>> songsList;
String kid,ktit,kart,kdur,kurl,EID;
TabHost tabHost;
TabHost.TabSpec spec;
Intent intent;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.t2);
tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
songsList = new ArrayList<HashMap<String, String>>();
final NewProdCompleteXMLParser parser = new NewProdCompleteXMLParser();
String xml = parser.getXmlFromUrl(URL);
final Document doc = parser.getDomElement(xml);
NodeList nl = doc.getElementsByTagName(KEY_SONG);
for (int i = 0; i < nl.getLength(); i++) {
map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
map.put(KEY_IDs, parser.getValue(e, KEY_IDs));
songsList.add(map);
kid=parser.getValue(e, KEY_IDs);
System.out.println("kid"+kid);
intent = new Intent().setClass(this, Tab1.class);
spec= tabHost.newTabSpec("hhj").setIndicator(kid)
.setContent(intent);
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(Color.WHITE);
}
tabHost.getTabWidget().setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_hover);
}
public void onTabChanged(String tabId) {
name=songsList.get(tabHost.getCurrentTab()).get("timetable_date");
System.out.println("on tab changed"+name);
/************ Called when tab changed *************/
//********* Check current selected tab and change according images *******/
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
}
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.tab_hover);
}
Log.i("tabs", "CurrentTab: "+tabHost.getCurrentTab());
while(tabHost.getCurrentTab()==1)
{
Intent intent1 = new Intent().setClass(this, Tab1.class);
spec.setContent(intent1);
//Add intent to tab
System.out.println("on tab changed"+name);
tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.tab_bg);
}
}
}
必须发送System.out.println("on tab changed"+name);。这个名字val(ie.fri17..sat 18.on each tab click to next Tab1 class)
public class Tab1 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
TabBar tb=new TabBar();
String name = tb.name;
System.out.println("on tab changed TT"+name);
}
}
【问题讨论】:
-
我已经更新了。你可以参考@keshav
标签: android android-layout android-intent android-fragments tabs