1. android listview内使用进度条乱序问题
首先判断首位不是"-",再判断字符串中没有小数点"."
满足这两个就是正整数 C语言中 变量都是先声明再使用,你声明成INT就是整型,关于正负就判断一下!
2. android 如何让listview 里的内容从左到右排列
可以用gallery或者水平滚动的ScrollView,不一定非要用ListView的
3. android listview 多个item 倒计时怎么做好
Handler+Timer+TimerTask实现:
Activity中代码:
public class ShopActivity extends Activity {
private ListView lv;
private ShopAdapter pmAdapter;
private Timer timer = new Timer();
private TimerTask timerTask;
private List<MyData> dataList;
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == 1) {
for (int i = 0; i < mMyMatchList.size(); i++) {
dataList.get(i).setServerDate(Long.valueOf(dataList.get(i).getServerDate())+ 1 + "");//这是服务器当前时间,以此时间为基数进行倒时计,因为服务器时间以秒为单位返回,所以咱们每隔1秒,把当前服务器时间+1,也可以把结束时间-1
serverTime = Long.valueOf(mMyMatchList.get(i).getServerDate());
pmAdapter.notifyDataSetChanged();
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_shop);
dataList=new ArrayList<MyData>();//接下来要从服务端取到数据,加入dataList中
lv= (ListView) this.findViewById(R.id.shop_lv);
pmAdapter = new ShopAdapter(ShopActivity.this, this);
lv.setAdapter(pmAdapter);
timerTask = new TimerTask() {
@Override
public void run() {
Message message = Message.obtain();
message.what = 1;
mHandler.sendMessage(message);
}
};
timer.schele(timerTask, 1000, 1000);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onDestroy() {
if (null != timer) {
timer.cancel();
}
super.onDestroy();
}
}
最后在适配器类ShopAdapter中,根据服务器返回的截止时间和服务器时间,把数据加上去就可以了:
TextView timeTv=findViewById();
timeTv.setText(getTimeFromInt(结束时间-服务器时间));
getTimeFromInt这个方法是计算时间差并转换成所需要格式的:
public String getTimeFromInt(long time) {
if (time <= 0) { return "已结束"; }
long day = time / (1 * 60 * 60 * 24);
long hour = time / (1 * 60 * 60) % 24;
long minute = time / (1 * 60) % 60;
long second = time / (1) % 60;
return "还剩:" + day + "天" + hour + "小时" + minute + "分" + second + "秒";
}
4. 安卓开发,SQLLite中,把数据显示到listview时候,怎么进行排序显示
SQL语句里有个排序的方法 order by 可以根据你数据库里的一些字段进行排列。要倒序的话就在字段名后面加 desc
5. 安卓listview的内容顺序问题
这个很简单啊
首先listview中的item的布局先按照你的顺序和设计需求写好4个textview
然后把收到的数据分别加载到这个item里面的textview就好了啊
6. android listView动态添加 顺序错乱
你用的集合是不是键值对的集合?如果是的话就不是根据你输入的时间保存的数据。
7. 安卓中怎么实现listview 条目拖动排序
SlideAndDragListView,可排序、可滑动item显示”菜单”的ListView。
SlideAndDragListView(SDLV)继承于Android的ListView,SDLV可以拖动item到SDLV的任意位置,其中包括了拖动item往上滑和往下滑;SDLV可以向右滑动item,像Android的QQ那样(QQ是向左滑),然后显现出来"菜单”之类的按钮。
8. Android 如何按时间先后显示ListView数据
解决方法:
lisrview绑定的是哪种adapter?我假设是最简单的arrayAdapter,其实原理都一样。
绑定adapter的数据大多数是数组。
数组的排序总会把?我记得是sort。
排序好再将数据绑定到adapter,然后adapter绑定到listview
9. android 中listview 的用法
1.在xml里面定义一个ListView,这个xml是一个activity的layout文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:layout_width="wrap_content" //定义一个listView
android:layout_height="wrap_content"
android:id="@+id/ListView01"
/>
</LinearLayout>
2.定义ListView每个条目的Layout,比如命名为listview_item.xml,用RelativeLayout实现:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:paddingBottom="4dip"
android:paddingLeft="12dip"
android:paddingRight="12dip">
<ImageView
android:paddingTop="12dip"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ItemImage"
/>
<TextView
android:text="TextView01"
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_width="fill_parent"
android:id="@+id/ItemTitle"
/>
<TextView
android:text="TextView02"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@+id/ItemTitle"
android:id="@+id/ItemText"
/>
</RelativeLayout>
3.在Activity里面调用和加入Listener,具体见注释:
package com.ray.test;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
public class TestListView extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//绑定Layout里面的ListView
ListView list = (ListView) findViewById(R.id.ListView01);
//生成动态数组,加入数据
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
for(int i=0;i<10;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.checked);//图像资源的ID
map.put("ItemTitle", "Level "+i);
map.put("ItemText", "Finished in 1 Min 54 Secs, 70 Moves! ");
listItem.add(map);
}
//生成适配器的Item和动态数组对应的元素,这里用SimpleAdapter作为ListView的数据源
//如果条目布局比较复杂,可以继承BaseAdapter来定义自己的数据源。
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.list_items,//ListItem的XML实现
//动态数组与ImageItem对应的子项
new String[] {"ItemImage","ItemTitle", "ItemText"},
//ImageItem的XML文件里面的一个ImageView,两个TextView ID
new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.ItemText}
);
//添加并且显示
list.setAdapter(listItemAdapter);
//添加点击
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
setTitle("点击第"+arg2+"个项目");
}
});
//添加长按点击
list.(new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
menu.setHeaderTitle("长按菜单-ContextMenu");
menu.add(0, 0, 0, "弹出长按菜单0");
menu.add(0, 1, 0, "弹出长按菜单1");
}
});
}
//长按菜单响应函数
@Override
public boolean onContextItemSelected(MenuItem item) {
setTitle("点击了长按菜单里面的第"+item.getItemId()+"个项目");
return super.onContextItemSelected(item);
}
}