日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

自定义listview和ProgressBar的简单使用

發布時間:2024/3/13 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 自定义listview和ProgressBar的简单使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?自定義listview和ProgressBar的簡單使用

先看效果圖

?

通過“+”和”-”按鈕來控制ProgressBar的進度,最大刻度為100,每次點擊按鈕進度加10或減10,當刻度超過100的時候刻度會從0重新開始。

?

MainActivity:

?

package com.example.zml4;import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast;/*** @author Bri* */ public class MainActivity extends Activity implements OnClickListener {ProgressBar pro;Button bt_plus, bt_sub, bt_next;TextView tv_show;int progress = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);pro = (ProgressBar) findViewById(R.id.progressBar1);bt_plus = (Button) findViewById(R.id.bt_plus);bt_sub = (Button) findViewById(R.id.bt_sub);bt_next = (Button) findViewById(R.id.bt_next);tv_show = (TextView) findViewById(R.id.tv_s);pro.setMax(100);pro.setProgress(progress);bt_plus.setOnClickListener(this);bt_sub.setOnClickListener(this);bt_next.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.bt_plus:progress += 10;if (progress > 100) {progress = 0;pro.setProgress(progress);} else {pro.setProgress(progress);}tv_show.setText(progress + "%");break;case R.id.bt_sub:progress -= 10;if (progress < 0) {progress = 0;pro.setProgress(progress);} else {pro.setProgress(progress);}tv_show.setText(progress + "%");break;case R.id.bt_next:Intent intent = new Intent(MainActivity.this, ListViewRatingBarActivity.class);startActivity(intent);break;}}public void author(View v) {Toast.makeText(this, "zml2015\n軟件工程\nQQ:107****340", Toast.LENGTH_SHORT).show();} }

?

?

?

布局文件:

?

?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.example.zml4.MainActivity" ><TextViewandroid:id="@+id/tv_s"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:text="0%" ></TextView><ProgressBarandroid:id="@+id/progressBar1"style="?android:attr/progressBarStyleHorizontal"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentTop="true"android:layout_marginTop="22dp" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center" ><Buttonandroid:id="@+id/bt_plus"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="+" ></Button><Buttonandroid:id="@+id/bt_sub"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="-" ></Button></LinearLayout><Buttonandroid:id="@+id/bt_next"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginTop="50dp"android:text="ListViewRatingBar" /><TextViewandroid:id="@+id/tv_author"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginBottom="20dp"android:clickable="true"android:gravity="center"android:onClick="author"android:text="點我~\(≧▽≦)/~" /></LinearLayout>

?

?

?

?

?

制作動態ListView,當RatingBar的星號數大于2顆的時候,名字變為大寫,反之小于等于2顆星的時候變為小寫

自定義Listview

?

package com.example.zml4;import android.app.Activity; import android.os.Bundle; import android.widget.ListView;/*** @author Bri* */ public class ListViewRatingBarActivity extends Activity {ListView lv;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.listview);lv = (ListView) findViewById(R.id.lv);String name[] = { "aa", "BB", "cFc", "DeD", "EE", "ff", "GG", "Ahh","bEE", "Eff", "fGG", "aa", "BB", "cc", "DD", "EE", "ff", "GG","hh", "EE", "ff", "GG" };lv.setAdapter(new MyAdapter(this, name));} }


自定義的適配器:

?

?

package com.example.zml4;import android.content.Context; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListAdapter; import android.widget.RatingBar; import android.widget.RatingBar.OnRatingBarChangeListener; import android.widget.TextView; import android.widget.Toast;/*** @author Bri* */ public class MyAdapter extends BaseAdapter implements ListAdapter {String data[];LayoutInflater inflater;Context context;public MyAdapter(Context context, String[] data) {this.data = data;inflater = LayoutInflater.from(context);this.context = context;}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn data.length;}@Overridepublic Object getItem(int arg0) {// TODO Auto-generated method stubreturn null;}@Overridepublic long getItemId(int arg0) {// TODO Auto-generated method stubreturn 0;}@Overridepublic View getView(int position, View view, ViewGroup arg2) {final int pos = position;view = inflater.inflate(R.layout.listview_item, null);final TextView tv = (TextView) view.findViewById(R.id.tv_name);final RatingBar rt = (RatingBar) view.findViewById(R.id.rb);rt.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {@Overridepublic void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) {String show;arg0.setRating(arg1);Toast.makeText(context, "星星數:" + arg1, 0).show();if (arg1 > 2) {show = data[pos].toUpperCase();} else {show = data[pos].toLowerCase();}tv.setText(show);Log.e("num", "星星數:" + arg1);}});if (tv.getText().equals("name"))tv.setText(data[pos]);return view;}// 懶得寫優化了,就不寫了static class ViewHolder {RatingBar rb;TextView tv;public ViewHolder(RatingBar rb, TextView tv) {this.rb = rb;this.tv = tv;}} }

?

?

自定義ListView的布局及其子布局

?

<?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" ><ListView android:id="@+id/lv"android:layout_width="match_parent"android:layout_height="match_parent"></ListView> </LinearLayout>

?

?

?

<?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="horizontal" android:gravity="center"><TextViewandroid:id="@+id/tv_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="name"/><RatingBar android:id="@+id/rb"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout>

?


完整源碼下載

?

?

?

?

?

?

總結

以上是生活随笔為你收集整理的自定义listview和ProgressBar的简单使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 精人妻无码一区二区三区 | 伊人av在线 | 97国产成人 | 青青草国产一区 | 特级做a爰片毛片免费69 | av免费在线观看网址 | 日韩黄片一区二区 | 男人的天堂日韩 | 国产精品一区网站 | 亚洲一区二区不卡视频 | 91午夜影院 | avwww.| 1区2区3区视频 | gai视频在线观看资源 | 歪歪视频在线观看 | av在线亚洲天堂 | 无码精品黑人一区二区三区 | 人妻少妇偷人精品无码 | 97人人视频| 亚洲视频你懂的 | 亚洲专区一 | 日韩国产二区 | 可以免费看污视频的网站 | 午夜精品网站 | 国产大学生自拍视频 | 97自拍偷拍视频 | www.超碰97.com| 国产情侣一区二区 | 成人av播放 | 成人国产精品 | 国产高清久久 | 亚洲一区二区三区久久久成人动漫 | 美女裸体网站久久久 | 一级特黄色大片 | 欧美一区二区三区四区五区六区 | 国产91免费在线观看 | 快色视频| 天天av天天操 | 天天天操操操 | 日韩欧美亚洲一区二区 | 亚洲精品aaa| 国产五区 | 亚洲av少妇一区二区在线观看 | 中文字幕2区 | 精品不卡一区 | 成人123区| 五月激情丁香网 | 美国一区二区 | 久艹在线观看视频 | 亚洲国产成人在线 | 不卡的av在线免费观看 | 人人爽人人草 | 欧美绿帽合集videosex | 亚洲图片自拍偷拍 | 人人草人人爱 | 日日夜夜免费精品 | 最新免费av网站 | av影片在线 | 美女脱光衣服让男人捅 | 中文字幕成人在线观看 | 波多野结衣乳巨码无在线 | 依依成人在线视频 | 大伊人久久 | 最新国产露脸在线观看 | 国模精品视频一区二区 | av免费网站在线观看 | 超碰这里只有精品 | 91麻豆精品国产理伦片在线观看 | 色婷婷色婷婷 | 大尺度激情吻胸视频 | 久操不卡| 伦理片av | 日韩欧美精品在线观看 | 天天色天天综合 | 色爽爽爽爽爽爽爽爽 | 日韩视频专区 | 三级小视频在线观看 | 天天躁夜夜操 | 国产第8页 | 激情爱爱网站 | 免费成人在线观看动漫 | 在线免费av片 | 午夜视频一区二区三区 | 视频二区在线观看 | 欧美日韩黄 | 久久久久久无码精品大片 | 黄色在线播放 | 在线综合av| 亚洲人交配视频 | 99精品热| 午夜资源网| 国产精品美女久久久久 | 亚洲AV无码一区二区三区少妇 | 国产噜噜噜噜噜久久久久久久久 | 国产在线精品成人欧美 | 看免费的毛片 | 天天操人人干 | www超碰在线| 粉嫩av一区二区 |