[Android]关于TabHost+ListView的问题.

在TabHost中添加一个ListView.这个ListView的作用类似文件管理器,并添加了OnItemChickListener.
点击ListView中所显示的目录(isDirectory),如果有下级目录就会在当前ListView显示下级目录,一直到没有目录或者到文件(File)为止.
问题:如何在TabHost中刷新ListView,而不是刷新整个Activity?
因为TabHost的默认标签为0角标,ListView是在1角标.当我第一次进入该Activity时,需要显示的是0角标的view.
注:这里的Activity继承的是Actviity,监听是构建了一个监听类,统一监听所有触发事件,ListView的Adapter的自定义的Adapter.
请各位高手不惜吝教...小弟(菜鸟)感激...

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
[Android]关于TabHost+ListView的问题.

在TabHost中添加一个ListView.这个ListView的作用类似文件管理器,并添加了OnItemChickListener. 点击ListView中所显示的目录(isDirectory),如果有下级目录就会在当前ListView显示下级目录,一直到没有目录或者到文件(File)为止. 问题:如何在TabHost中刷新ListView,而不是刷新整个Activity? 因为TabHost的默认标签为0角标,ListView是在1角标.当我第一次进入该Activity时,需要显示的是0角标的view. 注:这里的Activity继承的是Actviity,监听是构建了一个监听类,统一监听所有触发事件,ListView的Adapter的自定义的Adapter. 请各位高手不惜吝教...小弟(菜鸟)感激...

android ListView mListView.getChildAt(i)为空,求怎么解决?

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { for (int i = 0; i < mListView.getCount(); i++) { View callLogView = mListView.getChildAt(i); mRelativeLayout = (LinearLayout)callLogView.findViewById(R.id.myShow); if(i == position){ if(mRelativeLayout.getVisibility() == View.GONE){ mRelativeLayout.setVisibility(View.VISIBLE); } else{ mRelativeLayout.setVisibility(View.GONE); } }else{ mRelativeLayout.setVisibility(View.GONE); } } } }); 如题,代码以附上,我现在想做的事是在点击一项ListView后显示出一个布局,而其它项的ListView隐藏,但在超过 mListView.getChildCount()后会出现空指针,求解!

在viewpager和fragment中嵌套listview,出现setAdapter空指针情况。

在viewpager和fragment中嵌套listview,出现setAdapter空指针情况。 为了实现滑动切换界面,我写了三个fragment,在一个fragment中加入了一个listview,怎么启动都是空指针。 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference at com.example.tabhost_02.Fragment_Device.onActivityCreated(Fragment_Device.java:33) at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2619) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:904) at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303) at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439) at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079) at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869) at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824) at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1696) at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:299) at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:235) at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244) at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092) at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622) at android.view.View.measure(View.java:22002) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514) at android.widget.LinearLayout.measureVertical(LinearLayout.java:806) at android.widget.LinearLayout.onMeasure(LinearLayout.java:685) at android.view.View.measure(View.java:22002) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) at android.view.View.measure(View.java:22002) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143) at android.view.View.measure(View.java:22002) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580) at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:403) at android.view.View.measure(View.java:22002) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.view.View.measure(View.java:22002) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514) at android.widget.LinearLayout.measureVertical(LinearLayout.java:806) at android.widget.LinearLayout.onMeasure(LinearLayout.java:685) at android.view.View.measure(View.java:22002) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at com.android.internal.policy.DecorView.onMeasure(DecorView.java:721) at android.view.View.measure(View.java:22002) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2410) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1498) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1751) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) at android.view.Choreographer.doCallbacks(Choreographer.java:723) at android.view.Choreographer.doFrame(Choreographer.java:658) <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView5" android:layout_width="358dp" android:layout_height="wrap_content" android:text="状态详情" android:textColor="#000000" android:textSize="20sp" android:textStyle="bold" /> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="176dp" android:text="TextView" /> <TextView android:id="@+id/textView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="部件信息" android:textColor="#000000" android:textSize="20sp" android:textStyle="bold" /> <TextView android:id="@+id/textView6" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="温度传感器" android:textColor="#2196F3" android:textSize="18sp" android:textStyle="bold" /> <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> public class Fragment_Device extends Fragment { private List<Info> infos = new ArrayList<>(); private ListView device_info=null; public Fragment_Device(){ } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_device, container, false); initInfo(); return view; } public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initInfo(); } private void initInfo() { Info dev_1 = new Info("室内环境监控", "20摄氏度", "100小时", "2019-05-01 09:00:00"); infos.add(dev_1); Info dev_2 = new Info("室内环境监控", "25摄氏度", "100小时", "2019-05-01 09:08:00"); infos.add(dev_2); Info dev_3 = new Info("室内环境监控", "23摄氏度", "100小时", "2019-05-01 10:00:00"); infos.add(dev_3); Info dev_4 = new Info("室内环境监控", "28摄氏度", "100小时", "2019-05-01 10:30:00"); infos.add(dev_4); InfoAdapter infoAdapter = new InfoAdapter(infos,getContext()); View view = LayoutInflater.from(getContext()).inflate(R.layout.list_item,null); infos=view.findViewById(R.id.lv); device_info = view.findViewById(R.id.lv); device_info.setAdapter(infoAdapter); } }

tabHost的滑动效果监听不到

我的tabHost有三栏,都是listView,想加一个滑动切换tab的效果,结果发现不行,于是 用了个简单的来测试,发现如下问题。 情况一 ``` android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" /> </LinearLayout> ``` 情况二 ``` <LinearLayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:ems="10" /> </LinearLayout> ``` 这个tab里面只有这个EditText,就android:layout_height不同 然后就发现滑动效果在fill_parent的时候不反应了! 这是什么问题??? 下面是ACtivity的内容 ``` package com.mine.tabhostdemo2; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.util.Log; import android.view.GestureDetector; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class TabHostActivity extends FragmentActivity { private static TabHost tabHost; private GestureDetector detector=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tab_host); // tabHost = (TabHost) findViewById(R.id.tabhost); init(); if (detector==null){ detector= new GestureDetector(this, new MySimpleOnGestureListener()); } } private void init() { // TODO Auto-generated method stub tabHost = (TabHost) findViewById(R.id.tabhost); tabHost.setup(); TabSpec spec1 = tabHost.newTabSpec("1"); spec1.setIndicator("1", getResources().getDrawable(R.drawable.ic_launcher)); spec1.setContent(R.id.tab1); TabSpec spec2 = tabHost.newTabSpec("2"); spec2.setIndicator("2", getResources().getDrawable(R.drawable.ic_launcher)); spec2.setContent(R.id.tab2); TabSpec spec3 = tabHost.newTabSpec("3"); spec3.setIndicator("3", getResources().getDrawable(R.drawable.ic_launcher)); spec3.setContent(R.id.tab3); tabHost.addTab(spec1); tabHost.addTab(spec2); tabHost.addTab(spec3); //method one /*detector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if ((e2.getRawX() - e1.getRawX()) > 80) { showNext(); return true; } if ((e1.getRawX() - e2.getRawX()) > 80) { showPre(); return true; } return super.onFling(e1, e2, velocityX, velocityY); } });*/ } //method two private static class MySimpleOnGestureListener extends GestureDetector.SimpleOnGestureListener { public MySimpleOnGestureListener() { super(); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if ((e2.getRawX() - e1.getRawX()) > 80) { showNext(); return true; } if ((e1.getRawX() - e2.getRawX()) > 80) { showPre(); return true; } //Log.e(TAG, "onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)"); return super.onFling(e1, e2, velocityX, velocityY); } } @Override public boolean onTouchEvent(MotionEvent event) { if(detector!=null){ detector.onTouchEvent(event); }else{ Log.i("nimeide1", "no detector!!!!!!!!!!!!"); } return super.onTouchEvent(event); } static int i = 0; protected static void showPre() { // TODO Auto-generated method stub tabHost.setCurrentTab(i = i == 2 ? i = 0 : ++i); Log.i("kennet", i + ""); } protected static void showNext() { // TODO Auto-generated method stub tabHost.setCurrentTab(i = i == 0 ? i = 2 : --i); Log.i("kennet", i + ""); } } ```

自学Android开发 在模拟器运行闪退

初学者自写的程序 ,但是在模拟器下运行闪退!!该怎么改呀?? package com.example.work3; import java.util.ArrayList; import java.util.List; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.TabActivity; import android.content.DialogInterface; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.StrictMode; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.Spinner; import android.widget.TabHost; import android.widget.TextView; import android.os.Build; public class MainActivity extends TabActivity { private TabHost tabhost; private ListView listview; private ArrayAdapter<String> arr_adapter; private Spinner spinner; private List<String>list; private ArrayAdapter<String> adapter; private EditText et1,et2; private Button bt; String name; String value; String style; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); et1=(EditText) findViewById(R.id.editText1); et2=(EditText) findViewById(R.id.editText2); bt=(Button) findViewById(R.id.button1); setContentView(R.layout.activity_main); tabhost=getTabHost(); tabhost.addTab(tabhost.newTabSpec("菜单一").setIndicator("首页").setContent(R.id.tab1)); tabhost.addTab(tabhost.newTabSpec("菜单二").setIndicator("新增").setContent(R.id.tab2)); tabhost.addTab(tabhost.newTabSpec("菜单三").setIndicator("账单").setContent(R.id.tab3)); //按钮监听 提取信息 bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub name = et1.getText().toString(); value = et2.getText().toString(); style = spinner.getSelectedItem().toString(); } }); listview = (ListView) findViewById(R.id.listview); //新建适配器 String[]arr_data={"数据1","数据2","数据3","数据4","数据5"}; //ArrayAdapter(上下文,当前ListView加载的每一个列表项所对应的布局文件,数据源) arr_adapter =new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,arr_data); listview.setAdapter(arr_adapter); spinner=(Spinner) findViewById(R.id.spinner); //数据源 String[]list = {"1.日常食品支出","2.人情世故支出","3.出差旅游支出","4.服饰鞋帽支出","5.生活用品支出","6.其他支出"}; //新建适配器 adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list); //设置下拉样式 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //加载适配器 spinner.setAdapter(adapter); } //退出对话框 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK ) { // 创建退出对话框 AlertDialog isExit = new AlertDialog.Builder(this).create(); // 设置对话框标题 isExit.setTitle("系统提示"); // 设置对话框消息 isExit.setMessage("确定要退出吗"); // 添加选择按钮并注册监听 isExit.setButton("确定", listener); isExit.setButton2("取消", listener); // 显示对话框 isExit.show(); } return false; } /**监听对话框里面的button点击事件*/ DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case AlertDialog.BUTTON_POSITIVE:// "确认"按钮退出程序 finish(); break; case AlertDialog.BUTTON_NEGATIVE:// "取消"第二个按钮取消对话框 break; default: break; } } }; }

在fragment中的listView问题

在fragment中显示一个自定义listView,但是运行后什么也没显示。 public class Tab1 extends Fragment implements ListView.OnItemClickListener{ private ArrayList<Custom> fetch = new ArrayList<Custom>(); private ContactsAdapter adapter; private ListView lv; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState){ View v = inflater.inflate(R.layout.tab_layout, container, false); Custom one = new Custom("Hoang Ha", "01672286349"); Custom two = new Custom("Ha Link", "03203590176"); fetch.add(one); fetch.add(two); lv =(ListView)v.findViewById(R.id.list); adapter = new ContactsAdapter(getActivity(), fetch); lv.setAdapter(adapter); lv.setOnItemClickListener(this); return v; } public class Custom{ private String contactName; private String contactPhone; public Custom(String st1, String st2){ contactName = st1; contactPhone = st2; } public String getName(){ return contactName; } public String getPhone(){ return contactPhone; } public void setName(String st1){ contactName = st1; } public void setPhone(String st2){ contactPhone = st2; } } @Override public void onItemClick(AdapterView<?> ad, View v, int position, long id) { // TODO Auto-generated method stub } private class ContactsAdapter extends BaseAdapter{ private FragmentActivity activity; private LayoutInflater inflater; private ArrayList<Custom> data; public ContactsAdapter (FragmentActivity a, ArrayList<Custom> d){ activity = a; data = d; inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { // TODO Auto-generated method stub data.size(); return 0; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View v = convertView; v = inflater.inflate(R.layout.list_row, null); TextView contact_name = (TextView)v.findViewById(R.id.contact_name); TextView phone_number = (TextView)v.findViewById(R.id.phone_number); //final Custom custom = entries.get(position); final Custom custom = data.get(position); contact_name.setText(custom.getName()); phone_number.setText(custom.getPhone()); return v; } } } 这是列表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="vertical" android:background="@color/light_dark" android:padding="5dip" > <TextView android:id="@+id/contact_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/name" android:textColor="@color/white" android:typeface="sans" android:textSize="@dimen/font_medium" android:textStyle="bold"/> <TextView android:id="@+id/phone_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/name" android:textColor="@color/white" android:typeface="sans" android:textSize="@dimen/font_small" /> </LinearLayout>

android tab 变换监听器

我创建了三个Tab. Language (包括language 布局的language 类) Activation (包括Activation 布局的Activation类) Settings (包括Settings 布局的Settings 类) 在 settings 列表里改变 settings 可以隐藏language布局中的文字定义,然后再次点击language Tab的时候,文字翻译仍然还在。 我认为应该设置一个tab 变换监听器。 但是怎么实现tab变换监听器呢? TabActivity: package com.languagetranslate; import com.languagetranslate.Constants.Constants; import com.languagetranslate.dao.UserData; import android.app.Activity; import android.app.TabActivity; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.FrameLayout; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TabHost; import android.widget.TextView; import android.widget.TabHost.OnTabChangeListener; public class Screen1 extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.screen1); initializeTabs(); } private void initializeTabs() { TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, WordsClass.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("Words").setIndicator("Words") .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, ActivateClass.class); spec = tabHost.newTabSpec("Activitation").setIndicator("Activitation") .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, Settings.class); spec = tabHost.newTabSpec("Settings").setIndicator(".\n.\n.") .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(2); tabHost.setOnTabChangedListener(new OnTabChangeListener() { public void onTabChanged(String tabId) { if ( tabId == "Language" ){ Constants.TAGS_ENABLE = UserData.getTagSettings(getApplicationContext(), Constants.SETTINGS_FILE); if (Constants.TAGS_ENABLE == true) { LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); FrameLayout item = (FrameLayout)findViewById(android.R.id.tabcontent); View child = inflate.inflate(R.layout.wordlayout, null); child.findViewById(R.id.availabletags).setVisibility(View.VISIBLE); child.findViewById(R.id.tags).setVisibility(View.VISIBLE); item.addView(child); // // ((TextView) findViewById(R.id.availabletags)) // .setVisibility(View.VISIBLE); // ((ListView) findViewById(R.id.tags)) // .setVisibility(View.VISIBLE); } } } }); } }

hi 问几个android开发的问题

hi 问几个问题 1. 如果在ProgressBar上显示数字,是否原生支持 2. 我有个下载的业务 在一个Activity中点下载的同时可以在另外一个Activity中显示现在进度: 我直接诶在Activity中new Thread来作的,这样好不好的,一般时用什么方法作? 这样性能是否过得去 看我红色标题部分,我是通过Thread while true, 3. 我在已下载完毕的文件图标上放个勾勾,这个是图片合成作的,还是用android提供的工具做的? [code="java"] /** * */ package com.alibaba.cloudspace; import java.util.ArrayList; import java.util.List; import android.app.TabActivity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.GestureDetector; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.widget.ListView; import android.widget.TabHost; import android.widget.TextView; import android.widget.TabHost.OnTabChangeListener; public class TransStatusActivity extends TabActivity implements OnTabChangeListener { private GestureDetector gestureDetector; private UpdateProgressBarHandler progressBarHandler; private UpdateDownloadFilesHandler downloadFilesHandler; private ProgressBarListAdapter adapter = null; private DownloadCompleteListAdapter downloadCompleteAdapter = null; private ListView listView = null; private ListView listView2 = null; private TabHost transTabhost; private final String[] TAB_IDS = new String[] { "TRANS_TAB1", "TRANS_TAB2" }; private static FileMap DOWNLOAD_FILES = new FileMap(); private String email = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // TODO Get email. // email = getIntent().getExtras().getString(""); gestureDetector = new GestureDetector(this, new CLGestureDetector(this)); transTabhost = this.getTabHost(); LayoutInflater.from(this).inflate(R.layout.trans_status, transTabhost.getTabContentView(), true); transTabhost.addTab(transTabhost.newTabSpec(TAB_IDS[0]).setIndicator( createTabTextView(R.string.app_text_transfer)).setContent(R.id.transfer_tab)); transTabhost.addTab(transTabhost.newTabSpec(TAB_IDS[1]).setIndicator( createTabTextView(R.string.app_text_transfer_finish)).setContent( R.id.transfer_finish_tab)); // TODO 载入未完成的下载列表 progressBarHandler = new UpdateProgressBarHandler(); downloadFilesHandler = new UpdateDownloadFilesHandler(); adapter = new ProgressBarListAdapter(this, getTransStatusList()); listView = (ListView) findViewById(R.id.trans_status_list); listView.setAdapter(adapter); [color=red][b] new UpdateProgressBarThread().start(); new UpdateDownloadFileListThread().start();[/b][/color] downloadCompleteAdapter = new DownloadCompleteListAdapter(this, DOWNLOAD_FILES.get(email)); listView2 = (ListView) findViewById(R.id.download_complete_list); listView2.setAdapter(downloadCompleteAdapter); transTabhost.setOnTabChangedListener(this); } 。。。。 private List<TransStatus> getTransStatusList() { List<TransStatus> transStatus = new ArrayList<TransStatus>(); for (int i = 0; i < FileListActivity.downloading.size(); i++) { FileDownloaderTask t = FileListActivity.downloading.get(i); if (t.isCompleted()) { DOWNLOAD_FILES.add(email, t.getFile()); downloadFilesHandler.sendMessage(new Message()); FileListActivity.downloading.remove(i--); continue; } TransStatus s = new TransStatus(); s.setFid(t.getFile().getNodeId()); s.setTitle(t.getFile().getFileName()); s.setPercent(t.getPercent()); Log.d("DEBUG-TRANS-STATUS", "Percent:" + s.getPercent() + ", has read:" + t.getHasReadSize() + ", full size:" + t.getFile().getFullSize()); transStatus.add(s); } return transStatus; } class UpdateProgressBarThread extends Thread { public void run() { while (true) { Message msg = new Message(); try { Thread.sleep(100); } catch (InterruptedException e) { } progressBarHandler.sendMessage(msg); int i = 0; for (FileDownloaderTask f : FileListActivity.downloading) { if (f.isCompleted()) i++; } Log.e("", "Completed:" + i + ", downloading size:" + FileListActivity.downloading.size()); if (i >= FileListActivity.downloading.size()) break; } }; } class UpdateDownloadFileListThread extends Thread { public void run() { Message msg = new Message(); try { Thread.sleep(100); } catch (InterruptedException e) { } downloadFilesHandler.sendMessage(msg); }; } class UpdateProgressBarHandler extends Handler { @Override public void handleMessage(Message msg) { adapter = new ProgressBarListAdapter(TransStatusActivity.this, getTransStatusList()); listView = (ListView) findViewById(R.id.trans_status_list); listView.setAdapter(adapter); } } class UpdateDownloadFilesHandler extends Handler { @Override public void handleMessage(Message msg) { downloadCompleteAdapter = new DownloadCompleteListAdapter(TransStatusActivity.this, DOWNLOAD_FILES.get(email)); listView2 = (ListView) findViewById(R.id.download_complete_list); listView2.setAdapter(downloadCompleteAdapter); } } @Override public void onTabChanged(String tabId) { } private TextView createTabTextView(int rid) { TextView txtTabInfo = new TextView(this); txtTabInfo.setText(getResources().getString(rid)); txtTabInfo.setPadding(0, 5, 0, 0); txtTabInfo.setTextSize(11); txtTabInfo.setBackgroundResource(R.drawable.tab_normal); txtTabInfo.setTextColor(Color.DKGRAY); txtTabInfo.setGravity(Gravity.CENTER); txtTabInfo.setHeight(39); return txtTabInfo; } } [/code]

程序开始运行时强制关闭,Adapter方法出错(用来实现闹钟的时间列表)

package pcAlarm.pack; import java.util.Calendar; import java.util.Currency; import pcAlarm.pack.PCAlarmActivity; import android.app.Activity; import android.app.TimePickerDialog; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.provider.Contacts; import android.view.View; import android.widget.ArrayAdapter; import pcAlarm.pack.AlarmView; import pcAlarm.pack.AlarmView.AlarmData; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TabHost; import android.widget.TimePicker; public class PCAlarmActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tabHost = (TabHost)findViewById(android.R.id.tabhost); tabHost.setup(); tabHost.addTab(tabHost.newTabSpec("tabAlarm").setIndicator("闹钟").setContent(R.id.tabAlarm)); btnAddAlarm=(Button)findViewById(R.id.btnAddAlarm); lvListView=(ListView)findViewById(R.id.lvListView); adapter=new ArrayAdapter<PCAlarmActivity.AlarmData>(getContext(), android.R.layout.simple_list_item_1); lvListView.setAdapter(adapter); adapter.add(new AlarmData(System.currentTimeMillis())); btnAddAlarm.setOnClickListener(new OnClickListener() { private Calendar mcalender; @Override public void onClick(View v) { Calendar.getInstance().setTimeInMillis(System.currentTimeMillis()); mcalender = Calendar.getInstance(); int mHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int mMinute = Calendar.getInstance().get(Calendar.MINUTE); new TimePickerDialog(PCAlarmActivity.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // TODO Auto-generated method stub Calendar.getInstance().setTimeInMillis(System.currentTimeMillis()); Calendar.getInstance().set(Calendar.HOUR_OF_DAY, hourOfDay); Calendar.getInstance().set(Calendar.MINUTE, minute); Calendar.getInstance().set(Calendar.SECOND, 0); Calendar.getInstance().set(Calendar.MILLISECOND, 0); AlarmData add = new AlarmData(Calendar.getInstance().getTimeInMillis()); } }, mHour, mMinute, true).show(); } }); } private Context getContext() { // TODO Auto-generated method stub return null; } private Button btnAddAlarm; private ListView lvListView; private ArrayAdapter<AlarmData> adapter; private static class AlarmData{ public AlarmData(long time){ this.time=time; date= Calendar.getInstance(); timeLabel=String.format("%d月%d日 %d:%d", date.get(Calendar.MONTH)+1, date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.HOUR_OF_DAY), date.get(Calendar.MINUTE)); } public long getTime() { return time; } public String getTimeLabel() { return timeLabel; } @Override public String toString() { // TODO Auto-generated method stub return getTimeLabel(); } private String timeLabel=""; private long time=0; private Calendar date; } private TabHost tabHost; }

关于安卓button的findviewbyid导致程序报错,和adapter的使用错误

package com.example.mp3test; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import android.app.Activity; import android.database.Cursor; import android.media.MediaPlayer; import android.os.Bundle; import android.provider.MediaStore; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.SeekBar; import android.widget.SimpleAdapter; import android.widget.TabHost; import android.widget.TabHost.TabSpec; import android.widget.TabWidget; public class MainActivity extends Activity { private TabHost tabHost; private TabSpec specSongs; private TabSpec specArtists; private TabSpec specAlbums; private TabSpec specPlaylist; private MediaPlayer player; private SeekBar audioSeekbar; private Button playBtn; private Button pauseBtn; private Button nextBtn; private Button preBtn; private Button stopBtn; private ListView songsList; private ListView artistsList; private ListView albumsList; private ListView playList; private List<Map<String,Object>> dataList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); audioSeekbar = (SeekBar) findViewById(R.id.seekBar1); // playBtn = (Button) findViewById(R.id.imagebstart); // nextBtn = (Button) findViewById(R.id.imagebnext); // preBtn = (Button) findViewById(R.id.imagebpre); // stopBtn = (Button) findViewById(R.id.imagebstop); songsList = (ListView) findViewById(R.id.listSongs); artistsList = (ListView) findViewById(R.id.listArtists); albumsList = (ListView) findViewById(R.id.listAlbums); playList = (ListView) findViewById(R.id.listPlaylist); dataList = new ArrayList<Map<String,Object>>(); //init(); //set_tab_style(); add_tabs(); //set_Adapter(); } private void init(){ tabHost = (TabHost) findViewById(android.R.id.tabhost); audioSeekbar = (SeekBar) findViewById(R.id.seekBar1); playBtn = (Button) findViewById(R.id.imagebstart); nextBtn = (Button) findViewById(R.id.imagebnext); preBtn = (Button) findViewById(R.id.imagebpre); stopBtn = (Button) findViewById(R.id.imagebstop); songsList = (ListView) findViewById(R.id.listSongs); artistsList = (ListView) findViewById(R.id.listArtists); albumsList = (ListView) findViewById(R.id.listAlbums); playList = (ListView) findViewById(R.id.listPlaylist); dataList = new ArrayList<Map<String,Object>>(); } private void set_Adapter(){ setListAdpter(songsList, getMp3Infos("songs")); setListAdpter(artistsList, getMp3Infos("artists")); setListAdpter(albumsList, getMp3Infos("albums")); setListAdpter(playList, getMp3Infos("playlist")); } private void set_tab_style(){ LinearLayout layout = (LinearLayout)tabHost.getChildAt(0); TabWidget tw = (TabWidget)layout.getChildAt(0); } private void add_tabs(){ specSongs = tabHost.newTabSpec("Tab 1"); specSongs.setContent(R.id.tabSongs); specSongs.setIndicator("Songs"); tabHost.addTab(specSongs); specArtists = tabHost.newTabSpec("Tab 2"); specArtists.setContent(R.id.tabArtists); specArtists.setIndicator("Artists"); tabHost.addTab(specArtists); specAlbums = tabHost.newTabSpec("Tab 3"); specAlbums.setContent(R.id.tabAlbums); specAlbums.setIndicator("Albums"); tabHost.addTab(specAlbums); specPlaylist = tabHost.newTabSpec("Tab 4"); specPlaylist.setContent(R.id.tabPlaylist); specPlaylist.setIndicator("Playlist"); tabHost.addTab(specPlaylist); } public List<Mp3Info> getMp3Infos(String c){ Cursor cursor = null; if(c.equals("songs")){ cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); } else if(c.equals("artists")){ cursor = getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Artists.DEFAULT_SORT_ORDER); } else if(c.equals("albums")){ cursor = getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER); } else if(c.equals("playlist")){ cursor = getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER); } List<Mp3Info> mp3Infos = new ArrayList<Mp3Info>(); for(int i = 0; i < cursor.getCount(); ++i){ Mp3Info mp3info = new Mp3Info(); cursor.moveToNext(); String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM)); String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)); long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION)); int isMusic = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.IS_MUSIC)); if(isMusic != 0){ mp3info.title = title; mp3info.album = album; mp3info.artist = artist; mp3info.duration = duration; mp3Infos.add(mp3info); } } return mp3Infos; } public void setListAdpter(ListView mMusiclist, List<Mp3Info> mp3Infos) { for (Iterator iterator = mp3Infos.iterator(); iterator.hasNext();) { Mp3Info mp3Info = (Mp3Info) iterator.next(); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("title", mp3Info.getTitle()); map.put("Artist", mp3Info.getArtist()); map.put("pic", R.drawable.music); dataList.add(map); } SimpleAdapter mAdapter = new SimpleAdapter(this, dataList, R.layout.item, new String[] { "title", "Artist", "pic" }, new int[] {R.id.itemsongs, R.id.itemArtists, R.id.itempic }); mMusiclist.setAdapter(mAdapter); } public class Mp3Info{ private String title; private String album; private String artist; private long duration; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAlbum() { return album; } public void setAlbum(String album) { this.album = album; } public String getArtist() { return artist; } public void setArtist(String artist) { this.artist = artist; } public long getDuration() { return duration; } public void setDuration(long duration) { this.duration = duration; } } } ``` ``` 以上代码,谢谢

程序运行时强制关闭,可能为空指针

日志:java.lang.RuntimeException: Unable to start activity ComponentInfo{pcAlarm.pack/pcAlarm.pack.PCAlarmActivity}: java.lang.NumberFormatException: 空指针错误,可能在 private void readSaveAlarm(){ SharedPreferences sp =getContext().getSharedPreferences(PCAlarmActivity.class.getName(), Context.MODE_PRIVATE); String content=sp.getString(KEY_ALARM_LIST, null); if (content!=null) { String[] timeString=content.split(","); for (String string : timeString) { adapter.add(new AlarmData(Long.parseLong(string))); } } }方法里 package pcAlarm.pack; import java.util.ArrayList; import java.util.Calendar; import java.util.Currency; import java.util.List; import pcAlarm.pack.PCAlarmActivity; import android.app.Activity; import android.app.AlertDialog; import android.app.PendingIntent.OnFinished; import android.app.TimePickerDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.provider.Contacts; import android.view.View; import android.widget.ArrayAdapter; import pcAlarm.pack.AlarmView; import pcAlarm.pack.AlarmView.AlarmData; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TabHost; import android.widget.TimePicker; public class PCAlarmActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tabHost = (TabHost)findViewById(android.R.id.tabhost); tabHost.setup(); tabHost.addTab(tabHost.newTabSpec("tabAlarm").setIndicator("闹钟").setContent(R.id.tabAlarm)); btnAddAlarm=(Button)findViewById(R.id.btnAddAlarm); lvListView=(ListView)findViewById(R.id.lvListView); adapter=new ArrayAdapter<PCAlarmActivity.AlarmData>(getContext(), android.R.layout.simple_list_item_1); lvListView.setAdapter(adapter); adapter.add(new AlarmData(System.currentTimeMillis())); readSaveAlarm(); btnAddAlarm.setOnClickListener(new OnClickListener() { private Calendar mcalender; @Override public void onClick(View v) { Calendar.getInstance().setTimeInMillis(System.currentTimeMillis()); mcalender = Calendar.getInstance(); int mHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int mMinute = Calendar.getInstance().get(Calendar.MINUTE); new TimePickerDialog(PCAlarmActivity.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // TODO Auto-generated method stub Calendar.getInstance().setTimeInMillis(System.currentTimeMillis()); Calendar.getInstance().set(Calendar.HOUR_OF_DAY, hourOfDay); Calendar.getInstance().set(Calendar.MINUTE, minute); Calendar.getInstance().set(Calendar.SECOND, 0); Calendar.getInstance().set(Calendar.MILLISECOND, 0); AlarmData add = new AlarmData(Calendar.getInstance().getTimeInMillis()); saveAlarmList(); } }, mHour, mMinute, true).show(); } }); lvListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View arg1, final int position, long id) { new AlertDialog.Builder(getContext()).setTitle("操作选项").setItems(new CharSequence[]{"删除"}, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: deleteAlarm(position); break; default: break; } } }).setNegativeButton("取消", null).show(); return true; } }); } private void deleteAlarm(int position){ adapter.remove(adapter.getItem(position)); } private void saveAlarmList(){ Editor editor=getContext().getSharedPreferences(PCAlarmActivity.class.getCanonicalName(), Context.MODE_PRIVATE).edit(); StringBuffer sb=new StringBuffer(); for (int i = 0; i < adapter.getCount(); i ) { sb.append(adapter.getItem(i).getTime()).append(","); } String content = sb.toString().substring(0, sb.length()-1); editor.putString(KEY_ALARM_LIST, sb.toString().substring(0, sb.length())); System.out.println(); editor.commit(); }

fragment中的listView点击item打开另一个fragment

我在项目里创建了一个fragment(A),现在fragment(A)中有一个listView。我想通过点击这个listView中的item打开另一个fragment(B)该如何实现?本人新手,《第一行代码》中说用FragmentManager 和 FragmentTransaction的replace,但是加入当中点击没有任何反应。 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EquipInfo equipInfo=list.get(position); String se="小型游艺设备"; String be="大型游艺设备"; if(equipInfo.getEquipDes().equals(be)){ atFragment fragment=new atFragment(); ft=manager.beginTransaction(); ft.replace(R.id.content_layout,fragment); ft.commit(); } else if(equipInfo.getEquipDes().equals(se)){ } } });

安卓数据库改变后,界面的刷新问题

目前学习中遇到的一个问题,希望大神给予解决。 我的activity继承自tabActivity, 给里面的tabhost添加或者删除一个选项的时候,后台的数据库已经才做成功了。但是界面上的东西没办法立即刷新。 需要我退出当前activity然后再重新进来才能将界面刷新。 之前用的listview也存在这个问题,我用notifyDataSetChanged();这个函数解决了。但是现在是tabhost的选项卡添加问题,不知道怎么弄。 小弟刚学安卓,对一些基本的东西可能还不懂,希望有人能帮我找到解决这个问题的方法,万分感谢!

急用!请问,如何解决在tabhost中每个按钮下添加子页面?

子页面可以加载进入,但是子页面里面的响应事件点击没有反应。而且,如果子页面里面再引用其他页面,里面的内容也显示不出来。

Android页面的传值问题

在主框架底部定义一个导航栏,可以切换四个页面,子页面中有listview组件,页面可以显示,但是listview中的数据不知道怎么加进去,小弟初学,希望前辈帮帮忙!!!

两个Activity之间Intent跳转问题

public class Sports extends TabActivity implements OnTabChangeListener{ private TabHost myTabhost; protected int myMenuSettingTag=0; private ListView listView,listView2; private String strArr[] = {"野外登山","高山蹦极","徒步远足","海滩沐浴"}; private Button button1 = null; private CheckBox checkBox1,checkBox2,checkBox3,checkBox4,checkBox5,checkBox6; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkBox1=(CheckBox)findViewById(R.id.checkBox1); checkBox2=(CheckBox)findViewById(R.id.checkBox2); checkBox3=(CheckBox)findViewById(R.id.checkBox3); checkBox4=(CheckBox)findViewById(R.id.checkBox4); checkBox5=(CheckBox)findViewById(R.id.checkBox5); checkBox6=(CheckBox)findViewById(R.id.checkBox6); myTabhost=this.getTabHost(); LayoutInflater.from(this).inflate(R.layout.sports, myTabhost.getTabContentView(), true); myTabhost.setBackgroundResource(R.drawable.backgroud3); myTabhost .addTab(myTabhost.newTabSpec("One") .setIndicator("球类运动", getResources().getDrawable(R.drawable.tab1)) .setContent(R.id.tab1)); myTabhost .addTab(myTabhost.newTabSpec("Two") .setIndicator("水上项目", getResources().getDrawable(R.drawable.tab2)) .setContent(R.id.tab2)); myTabhost .addTab(myTabhost.newTabSpec("Three") .setIndicator("野外项目", getResources().getDrawable(R.drawable.tab3)) .setContent(R.id.tab3)); listView=(ListView)findViewById(R.id.listView); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, strArr); listView.setAdapter(arrayAdapter); myTabhost .addTab(myTabhost.newTabSpec("Four") .setIndicator("专业健身", getResources().getDrawable(R.drawable.tab4)) .setContent(R.id.tab4)); listView2=(ListView)findViewById(R.id.listView2); SimpleAdapter adapter = new SimpleAdapter(this,getList(), R.layout.vlist, new String[]{"title","img"}, new int[]{R.id.title,R.id.img}); listView2.setAdapter(adapter); myTabhost.setOnTabChangedListener(this); myTabhost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { // TODO Auto-generated method stub } }); } private ArrayList<HashMap<String, Object>> getList() { ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("title", "器械运动(拉力器、俯卧撑等)"); map.put("img", R.drawable.sports1); list.add(map); map = new HashMap<String, Object>(); map.put("title", "有氧运动(跑步、健美操等)"); map.put("img", R.drawable.sports2); list.add(map); map = new HashMap<String, Object>(); map.put("title", "拉伸运动(瑜伽、普拉提等)"); map.put("img", R.drawable.sports3); list.add(map); return list; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if(keyCode==KeyEvent.KEYCODE_BACK){ Intent intent=new Intent(); intent.setClass(Sports.this,MainActivity.class); startActivity(intent); Sports.this.finish(); } return super.onKeyDown(keyCode, event); } @Override public void onTabChanged(String arg0) { // TODO Auto-generated method stub if (arg0.equals("One")) { button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Dialog dialog=new AlertDialog.Builder(Sports.this) .setTitle("状态") .setMessage("本程序由Easy制作\nVersion 0.01") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }).create(); dialog.show(); } }); } if (arg0.equals("Two")) { myMenuSettingTag = 2; } if (arg0.equals("Three")) { myMenuSettingTag = 3; } if (arg0.equals("Four")) { myMenuSettingTag = 4; } } } 这是sports.java public class SportsCheck extends Activity { private Button button01 = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sports); button01=(Button)findViewById(R.id.button1); button01.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent=new Intent(); intent.setClass(SportsCheck.this,SportsCheck1.class); startActivity(intent); SportsCheck.this.finish(); } }); } public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if(keyCode==KeyEvent.KEYCODE_BACK){ Intent intent=new Intent(); intent.setClass(SportsCheck.this,SportsCheck1.class); startActivity(intent); SportsCheck.this.finish(); } return super.onKeyDown(keyCode, event); } } 这是Sportscheck.Java public class SportsCheck1 extends Activity { private Button button1=null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sportscheck1); button1=(Button)findViewById(R.id.back); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent=new Intent(); intent.setClass(SportsCheck1.this,SportsCheck.class); startActivity(intent); SportsCheck1.this.finish(); } }); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if(keyCode==KeyEvent.KEYCODE_BACK){ Intent intent=new Intent(); intent.setClass(SportsCheck1.this,SportsCheck.class); startActivity(intent); SportsCheck1.this.finish(); } return super.onKeyDown(keyCode, event); } } 这是sportscheck1.java ``` ```

求安卓音乐播放器的按专辑显示列表的实现代码

想做一个音乐播放器,实现专辑列表的功能,按专辑显示列表,点击某个专辑能显示该专辑里对应的歌曲, 还有通过服务实现后台播放也有点问题,都写好了可就是播不出来,求大神指导,最好附上代码和注释,新手菜鸟一个

viewpager中的两个Fragment,点击FB中的按钮跳转到FragmentA

ViewPager中有FragmentA和FragmentB,点击FragmentA中的按钮,跳转到FragmentA 跪求大神解答

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

Linux 会成为主流桌面操作系统吗?

整理 |屠敏出品 | CSDN(ID:CSDNnews)2020 年 1 月 14 日,微软正式停止了 Windows 7 系统的扩展支持,这意味着服役十年的 Windows 7,属于...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

学习总结之HTML5剑指前端(建议收藏,图文并茂)

前言学习《HTML5与CSS3权威指南》这本书很不错,学完之后我颇有感触,觉得web的世界开明了许多。这本书是需要有一定基础的web前端开发工程师。这本书主要学习HTML5和css3,看...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

搜狗输入法也在挑战国人的智商!

故事总是一个接着一个到来...上周写完《鲁大师已经彻底沦为一款垃圾流氓软件!》这篇文章之后,鲁大师的市场工作人员就找到了我,希望把这篇文章删除掉。经过一番沟通我先把这篇文章从公号中删除了...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

新一代神器STM32CubeMonitor介绍、下载、安装和使用教程

关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang最近ST官网悄悄新上线了一款比较强大的工具:STM32CubeMonitor V1.0.0。经过我研究和使用之...

记一次腾讯面试,我挂在了最熟悉不过的队列上……

腾讯后台面试,面试官问:如何自己实现队列?

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

冒泡排序动画(基于python pygame实现)

本项目效果初始截图如下 动画见本人b站投稿:https://www.bilibili.com/video/av95491382 本项目对应github地址:https://github.com/BigShuang python版本:3.6,pygame版本:1.9.3。(python版本一致应该就没什么问题) 样例gif如下 ======================= 大爽歌作,mad

Redis核心原理与应用实践

Redis核心原理与应用实践 在很多场景下都会使用Redis,但是到了深层次的时候就了解的不是那么深刻,以至于在面试的时候经常会遇到卡壳的现象,学习知识要做到系统和深入,不要把Redis想象的过于复杂,和Mysql一样,是个读取数据的软件。 有一个理解是Redis是key value缓存服务器,更多的优点在于对value的操作更加丰富。 安装 yum install redis #yum安装 b...

现代的 “Hello, World”,可不仅仅是几行代码而已

作者 |Charles R. Martin译者 | 弯月,责编 | 夕颜头图 |付费下载自视觉中国出品 | CSDN(ID:CSDNnews)新手...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

!大部分程序员只会写3年代码

如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

HTTP与HTTPS的区别

面试官问HTTP与HTTPS的区别,我这样回答让他竖起大拇指!

程序员毕业去大公司好还是小公司好?

虽然大公司并不是人人都能进,但我仍建议还未毕业的同学,尽力地通过校招向大公司挤,但凡挤进去,你这一生会容易很多。 大公司哪里好?没能进大公司怎么办?答案都在这里了,记得帮我点赞哦。 目录: 技术氛围 内部晋升与跳槽 啥也没学会,公司倒闭了? 不同的人脉圈,注定会有不同的结果 没能去大厂怎么办? 一、技术氛围 纵观整个程序员技术领域,哪个在行业有所名气的大牛,不是在大厂? 而且众所...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

立即提问