成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

如何將Android應(yīng)用中導(dǎo)航欄在分頁(yè)中顯示

今天就跟大家聊聊有關(guān)如何將Android應(yīng)用中導(dǎo)航欄在分頁(yè)中顯示,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)企業(yè)建站,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),專(zhuān)注于網(wǎng)站建設(shè)技術(shù),精于網(wǎng)頁(yè)設(shè)計(jì),有多年建站和網(wǎng)站代運(yùn)營(yíng)經(jīng)驗(yàn),設(shè)計(jì)師為客戶打造網(wǎng)絡(luò)企業(yè)風(fēng)格,提供周到的建站售前咨詢和貼心的售后服務(wù)。對(duì)于網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)中不同領(lǐng)域進(jìn)行深入了解和探索,創(chuàng)新互聯(lián)在網(wǎng)站建設(shè)中充分了解客戶行業(yè)的需求,以靈動(dòng)的思維在網(wǎng)頁(yè)中充分展現(xiàn),通過(guò)對(duì)客戶行業(yè)精準(zhǔn)市場(chǎng)調(diào)研,為客戶提供的解決方案。

當(dāng)頁(yè)面條目過(guò)多的時(shí)候需要分頁(yè),要在布局中顯示出分頁(yè)的相關(guān)布局,使用android:layout_weight="11"

activity_call_safe.xml

<&#63;xml version="1.0" encoding="utf-8"&#63;>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
  <TextView 
 
   android:text="黑名單管理"
    />
  <FrameLayout 
    android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_weight="11"
    >
    <LinearLayout 
      android:id="@+id/ll_pb"
      android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:visibility="invisible"
    android:orientation="vertical"
    >
    <ProgressBar
      android:layout_width="wrap_content"
    android:layout_height="wrap_content"
      />
    <TextView 
      android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="玩命加載中..."
      />
    </LinearLayout>
   <include 
     android:id="@+id/list_view_callsafe"
     layout="@layout/list_view_callsafe"/>
  </FrameLayout>
  <LinearLayout 
    android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
    >
    <Button 
      android:onClick="prePage"
      android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="上一頁(yè)"
    android:layout_weight="1"
      />
 <Button 
      android:onClick="nextPage"
      android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="下一頁(yè)"
    android:layout_weight="1"
      /> 
 <Button 
      android:onClick="jump"
      android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="跳轉(zhuǎn)"
    android:layout_weight="1"
      /> 
     <EditText 
      android:id="@+id/et_page_number"
      android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
       />
     <TextView 
      android:id="@+id/tv_page_number"
      android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0/12"
    android:textSize="20sp"
    android:layout_weight="1"
       />         
  </LinearLayout>
</LinearLayout>

邏輯文件,實(shí)現(xiàn)分頁(yè)顯示,頁(yè)面的跳轉(zhuǎn),頁(yè)數(shù)的顯示,數(shù)據(jù)的刪除同時(shí)更新ListView

package com.ldw.safe.Activity;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.ldw.safe.R;
import com.ldw.safe.adapter.MyBaseAdapter;
import com.ldw.safe.bean.BlackNumberInfo;
import com.ldw.safe.db.dao.BlackNumberDao;
public class CallSafeActivity extends Activity {
 private ListView list_view_callsafe;
 private List<BlackNumberInfo> blackNumberInfos;
 private LinearLayout ll_pb;
 private BlackNumberDao dao;
 private TextView tv_page_number;
 private int pageNumber;
 private int mPageSize = 20;//每一頁(yè)顯示多少數(shù)據(jù)
 private int mCurrentPageNumber = 0;//當(dāng)前頁(yè)面
 private int totalPage;
 private CallSafeAdapter adapter;
 @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_call_safe);
    initUi();
    initData();
 }
 //初始化數(shù)據(jù)
 private Handler handler = new Handler(){
 @Override
    public void handleMessage(Message msg) {
  //通過(guò)總數(shù),和每頁(yè)顯示多少條顯示有多少條數(shù)據(jù)
  tv_page_number.setText(mCurrentPageNumber + "/" + totalPage);
  //數(shù)據(jù)初始化結(jié)束,關(guān)閉家在全的展示
  ll_pb.setVisibility(View.INVISIBLE);
  adapter = new CallSafeAdapter(blackNumberInfos, CallSafeActivity.this);
  //配置適配器
  list_view_callsafe.setAdapter(adapter);
 }
 };
 private EditText et_page_number;
 //初始化數(shù)據(jù)
 private void initData() {
 //防止阻塞主線程,在子線程中初始化數(shù)據(jù)(后期數(shù)據(jù)會(huì)很多)
 new Thread(){
  @Override
  public void run(){
  dao = new BlackNumberDao(CallSafeActivity.this);
  //獲取到總條數(shù)和頁(yè)數(shù)
  totalPage = dao.getTotalNumber() / mPageSize;
  //獲取到表的所有數(shù)據(jù)
  //blackNumberInfos = dao.findAll();
  //分頁(yè)顯示數(shù)據(jù)
  blackNumberInfos = dao.findPar(mCurrentPageNumber, mPageSize);
  handler.sendEmptyMessage(0);
  }
 }.start();
 }
 //初始化UI
 private void initUi() {
 ll_pb = (LinearLayout) findViewById(R.id.ll_pb);
    //初始化的時(shí)候展示加載的圓圈
    ll_pb.setVisibility(View.VISIBLE);
 list_view_callsafe = (ListView) findViewById(R.id.list_view_callsafe);
 tv_page_number = (TextView) findViewById(R.id.tv_page_number);
 et_page_number = (EditText) findViewById(R.id.et_page_number);
 }
 //對(duì)代碼進(jìn)行優(yōu)化,繼承自定義MyBaseAdapter,MyBaseAdapter繼承自BaseAdapter封裝一些常用的方法
 private class CallSafeAdapter extends MyBaseAdapter<BlackNumberInfo>{
 private CallSafeAdapter(List lists, Context mContext){
  super(lists, mContext);
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  //谷歌推出的優(yōu)化方案
  ViewHolder holder;
  if(convertView == null){
  convertView = View.inflate(CallSafeActivity.this, R.layout.item_call_safe, null);
  holder = new ViewHolder();
  holder.tv_number = (TextView) convertView.findViewById(R.id.tv_number);
  holder.tv_mode = (TextView) convertView.findViewById(R.id.tv_mode);
  holder.iv_delete = (ImageView) convertView.findViewById(R.id.iv_delete);
  convertView.setTag(holder);
  }else{
  holder = (ViewHolder) convertView.getTag();
  }
  holder.tv_number.setText(lists.get(position).getNumber());
  String mode = lists.get(position).getMode();
  if(mode.equals("1")){
  holder.tv_mode.setText("電話和短信攔截");
  }else if(mode.equals("2")){
  holder.tv_mode.setText("電話攔截");
  }else if(mode.equals("3")){
  holder.tv_mode.setText("短信攔截");
  }
  final BlackNumberInfo info = lists.get(position);
  //監(jiān)聽(tīng)刪除數(shù)據(jù)按鈕,刪除數(shù)據(jù)
  holder.iv_delete.setOnClickListener(new OnClickListener(){
  @Override
  public void onClick(View v) {
   String number = info.getNumber();
   boolean result = dao.delete(number);
   if(result){
   Toast.makeText(CallSafeActivity.this, "刪除成功", Toast.LENGTH_SHORT).show();
   lists.remove(info);
   //更新ListView
   adapter.notifyDataSetChanged();
   }else{
   Toast.makeText(CallSafeActivity.this, "刪除失敗", Toast.LENGTH_SHORT).show();
   }
  }
  });
  return convertView;
  /*
  //谷歌推出的優(yōu)化方案
  ViewHolder holder;
  if(convertView == null){
  convertView = View.inflate(CallSafeActivity.this, R.layout.item_call_safe, null);
  holder = new ViewHolder();
  holder.tv_number = (TextView) convertView.findViewById(R.id.tv_number);
  holder.tv_mode = (TextView) convertView.findViewById(R.id.tv_mode);
  convertView.setTag(holder);
  }else{
  holder = (ViewHolder) convertView.getTag();
  }
  holder.tv_number.setText(blackNumberInfos.get(position).getNumber());
  String mode = blackNumberInfos.get(position).getMode();
  if(mode.equals("1")){
  holder.tv_mode.setText("電話和短信攔截");
  }else if(mode.equals("2")){
  holder.tv_mode.setText("電話攔截");
  }else if(mode.equals("3")){
  holder.tv_mode.setText("短信攔截");
  }
  return convertView;
  */
  /*初步的優(yōu)化
  convertView = View.inflate(CallSafeActivity.this, R.layout.item_call_safe, null);
  TextView tv_number = (TextView) convertView.findViewById(R.id.tv_number);
  TextView tv_mode = (TextView) convertView.findViewById(R.id.tv_mode);
  tv_number.setText(blackNumberInfos.get(position).getNumber());
  String mode = blackNumberInfos.get(position).getMode();
  if(mode.equals("1")){
  tv_mode.setText("電話和短信攔截");
  }else if(mode.equals("2")){
  tv_mode.setText("電話攔截");
  }else if(mode.equals("3")){
  tv_mode.setText("短信攔截");
  }
  return convertView;
  */
  /*傳統(tǒng)的方式
  View view = View.inflate(CallSafeActivity.this, R.layout.item_call_safe, null);
  TextView tv_number = (TextView) view.findViewById(R.id.tv_number);
  TextView tv_mode = (TextView) view.findViewById(R.id.tv_mode);
  tv_number.setText(blackNumberInfos.get(position).getNumber());
  String mode = blackNumberInfos.get(position).getMode();
  if(mode.equals("1")){
  tv_mode.setText("電話和短信攔截");
  }else if(mode.equals("2")){
  tv_mode.setText("電話攔截");
  }else if(mode.equals("3")){
  tv_mode.setText("短信攔截");
  }
  return view;
  */
 } 
 }
 static class ViewHolder{
 TextView tv_number;
 TextView tv_mode;
 ImageView iv_delete;
 }
 /*
 * 上一頁(yè)
 */
 public void prePage(View v){
 //頁(yè)碼不能超過(guò)范圍
 if(mCurrentPageNumber <= 0){
  Toast.makeText(this, "這已經(jīng)是第一頁(yè)", Toast.LENGTH_SHORT).show();
  return;
 }
 mCurrentPageNumber --;
 initData();
 }
 /*
 * 下一頁(yè)
 */
 public void nextPage(View v){
 //頁(yè)碼不能超過(guò)范圍
 if(mCurrentPageNumber >= totalPage - 1){
  Toast.makeText(this, "這已經(jīng)是最后一頁(yè)", Toast.LENGTH_SHORT).show();
  return;
 }
 mCurrentPageNumber ++;
 initData();
 }
 /*
 * 跳轉(zhuǎn)頁(yè)面
 */
 public void jump(View v){
 String jump_page = et_page_number.getText().toString();
 if(TextUtils.isEmpty(jump_page)){
  Toast.makeText(this, "請(qǐng)輸入正確的頁(yè)碼", Toast.LENGTH_SHORT).show();
 }else{
  //讀取的字符串轉(zhuǎn)換成int
  int pageNumber = Integer.parseInt(jump_page);
  if(pageNumber >=0 && pageNumber<= totalPage - 1){
  mCurrentPageNumber = pageNumber;
  initData();
  }else{
  Toast.makeText(this, "請(qǐng)輸入正確的頁(yè)碼", Toast.LENGTH_SHORT).show();
  }
 }
 }
}

看完上述內(nèi)容,你們對(duì)如何將Android應(yīng)用中導(dǎo)航欄在分頁(yè)中顯示有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

新聞標(biāo)題:如何將Android應(yīng)用中導(dǎo)航欄在分頁(yè)中顯示
當(dāng)前鏈接:http://jinyejixie.com/article26/jopcjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、手機(jī)網(wǎng)站建設(shè)、面包屑導(dǎo)航網(wǎng)站排名、網(wǎng)站建設(shè)響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)
泰宁县| 徐闻县| 灵石县| 城固县| 阳江市| 瓮安县| 杂多县| 集贤县| 嵊泗县| 平邑县| 瑞金市| 吉首市| 鹤峰县| 长沙县| 静安区| 肇源县| 玛沁县| 丹棱县| 临海市| 乌鲁木齐县| 石嘴山市| 余姚市| 辽宁省| 页游| 巴中市| 永康市| 珠海市| 黄陵县| 彩票| 铁岭县| 商丘市| 深水埗区| 阳山县| 田林县| 陕西省| 化隆| 绩溪县| 绍兴县| 西丰县| 都兰县| 三江|