首页 > 其他分享 >Android的ListView分页功能(上滑加载更多)

Android的ListView分页功能(上滑加载更多)

时间:2024-01-30 22:57:56浏览次数:27  
标签:int public context new import Android ListView android 加载

Android的ListView分页功能(上滑加载更多)

  首先要定义一个footer.xml作为进度条和提示加载中的底部布局,代码如下:

复制代码
    <LinearLayout
        android:id="@+id/load_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:paddingBottom="10dip"
        android:paddingTop="10dip"
        tools:ignore="UselessParent" >

        <ProgressBar
            style="?android:attr/progressBarStyleLargeInverse"
            android:layout_width="30dp"
            android:layout_height="30dp" />
        
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="正在加载......"
            android:textSize="16sp"
            tools:ignore="HardcodedText" />

    </LinearLayout>
复制代码

  这样的显示效果就是这样的:

  

  然后自定义一个LoadListView,继承自ListView,实现其三个构造方法:

复制代码
    public LoadListView(Context context) {
        super(context);        
        initView(context);
    }
    public LoadListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }
    public LoadListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView(context);
    }
复制代码

  其中initView()是通过inflater初始化布局的,代码:

复制代码
    private void initView(Context context){
        LayoutInflater inflater = LayoutInflater.from(context);
        footer = inflater.inflate(R.layout.footer, null);
        footer.findViewById(R.id.load_layout).setVisibility(GONE);
        this.addFooterView(footer);
        this.setOnScrollListener(this);
    }
复制代码

  然后,实现实现它的滑动事件接口,(详见代码,这里只说过程),目的是为了监听ListView上滑到底部的时候,显示那个【加载更多...】提示信息,然后实现加载更多的函数运行,达到加载出更多数据。

  那么问题来了,加在了更多数据是重新设置数据适配器吗?答案当然是不可以重新设置,这里我们首先判断adapter是否为空,如果是空的,就setAdaper(),如果不是,其实就是加载更多以后,我们不去重新设置,而是调用this.notifyDataSetChanged();  //当有数据变化的时候,ListView会自动刷新界面。这样很好的保证了数据不会重新设置,效果还不错。

            if(adapter == null){
                adapter = new FenleiAdapter(FenleiActivity.this, newsBeans);
                mListView.setAdapter(adapter);
            }else {
                adapter.onDateChange(newsBeans);
            }
    public void onDateChange(List<FenleiBean> mList) {
        // TODO Auto-generated method stub
        this.mList = mList;
        this.notifyDataSetChanged();  //当有数据变化的时候,自动刷新界面
        
    }

  继续,这个时候我们会遇到一个问题,就是在自定义类LoadListView中,怎么去调用MainActivity中的方法,答案是接口回调,大概的意思就是在LoadListView中定义一个接口,然后去MainActivity具体实现这个接口,调用的时候,通过ListView变量来调用,具体我也只是大致明白这个意思,如果不明白可以再百度一下。

  当ListView通过findViewById()找到控件id的时候,不要忘了将这个接口设置给ListView,代码是mListView.setInterface(this);

  最后的最后要在加载完数据之后,去把提示消息设置为隐藏,这样,整个就大功告成了!!!

  最后的效果如图:

   

        [上滑效果]                [加载更多以后的效果]

LoadListView.java源码(具体还要根据你的项目去写)

package com.tdyl.consult.fenlei;

import com.tdyl.consult.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;

public class LoadListView extends ListView implements OnScrollListener {

    View footer; 
    int totalItemCount;
    int lastVisibleItem;
    boolean isLoading;
    ILoadListener2 iListener2;
    public LoadListView(Context context) {
        super(context);        
        initView(context);
    }
    public LoadListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }
    public LoadListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView(context);
    }
    
    private void initView(Context context){
        LayoutInflater inflater = LayoutInflater.from(context);
        footer = inflater.inflate(R.layout.footer, null);
        footer.findViewById(R.id.load_layout).setVisibility(GONE);
        this.addFooterView(footer);
        this.setOnScrollListener(this);
    }
    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        this.lastVisibleItem = firstVisibleItem + visibleItemCount;
        this.totalItemCount = totalItemCount;
    }
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollStatus) {
        if(totalItemCount == lastVisibleItem
                && scrollStatus == SCROLL_STATE_IDLE){
            if(!isLoading){
                isLoading = true;
                footer.findViewById(R.id.load_layout).setVisibility(VISIBLE);
                //加载更多数据
                iListener2.onLoad();
            }
        }
    }
    
    public void loadComplete(){
        isLoading = false;
        footer.findViewById(R.id.load_layout).setVisibility(GONE);
    }
    
    public void setInterface(ILoadListener2 iListener2){
        this.iListener2 = iListener2;
    }
    
    public interface ILoadListener2{
        public void onl oad();
    }

}
复制代码
package com.tdyl.consult.fenlei;

import com.tdyl.consult.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;

public class LoadListView extends ListView implements OnScrollListener {

    View footer; 
    int totalItemCount;
    int lastVisibleItem;
    boolean isLoading;
    ILoadListener2 iListener2;
    public LoadListView(Context context) {
        super(context);        
        initView(context);
    }
    public LoadListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }
    public LoadListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView(context);
    }
    
    private void initView(Context context){
        LayoutInflater inflater = LayoutInflater.from(context);
        footer = inflater.inflate(R.layout.footer, null);
        footer.findViewById(R.id.load_layout).setVisibility(GONE);
        this.addFooterView(footer);
        this.setOnScrollListener(this);
    }
    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        this.lastVisibleItem = firstVisibleItem + visibleItemCount;
        this.totalItemCount = totalItemCount;
    }
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollStatus) {
        if(totalItemCount == lastVisibleItem
                && scrollStatus == SCROLL_STATE_IDLE){
            if(!isLoading){
                isLoading = true;
                footer.findViewById(R.id.load_layout).setVisibility(VISIBLE);
                //加载更多数据
                iListener2.onLoad();
            }
        }
    }
    
    public void loadComplete(){
        isLoading = false;
        footer.findViewById(R.id.load_layout).setVisibility(GONE);
    }
    
    public void setInterface(ILoadListener2 iListener2){
        this.iListener2 = iListener2;
    }
    
    public interface ILoadListener2{
        public void onl oad();
    }

}
复制代码

MainActivity.java源码(我这里叫FenleiActivity.java,道理是一样的)


复制代码

package com.tdyl.consult.fenlei;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.tdyl.consult.R;
import com.tdyl.consult.fenlei.LoadListView.ILoadListener2;
import com.tdyl.consult.otochat.ChatOtoActivity;

public class FenleiActivity extends Activity implements ILoadListener2 {

    private LoadListView mListView;
    private String user_fenlei = "";
    private TextView title_name;
    int number = 10;
    FenleiAdapter adapter = null;

    ArrayList <HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();  //用来存放用户信息
    HashMap<String, Object> map = new HashMap<String, Object>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_fenlei);
        title_name = (TextView) findViewById(R.id.id_top_fenlei);
        mListView = (LoadListView) findViewById(R.id.lv_main);
        mListView.setInterface(this);
        Intent intent = getIntent();
        user_fenlei = intent.getStringExtra("user_fenlei");
        //-----------------------------------------------------------------------------
        title_name.setText(user_fenlei+"专家");
        new NewsAsynkTask().execute(number);
    }

    /**
     * 将url对应的json格式数据转化为我们缩封装的NewsBean对象
     * @param url
     * @return
     */
    private List<FenleiBean> getJsonData(int number){
        List<FenleiBean> newsBeanList = new ArrayList<FenleiBean>();
        //-----------------------------------------------------------------------------
        searchTop10(number);
        FenleiBean newsBean;
        if(list.size() == 0)
        {
            new AlertDialog.Builder(this)
            .setIcon(R.drawable.icon_menu)
            .setTitle("温馨小提示")
            .setMessage("没有要搜寻的专家分类")
            .setPositiveButton("立刻返回搜索界面...", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    finish();
                }
            }).show();
        }
        for(int i=0;i<list.size();i++)
        {
            newsBean = new FenleiBean();
            HashMap<String, Object> map1 = new HashMap<String, Object>();
            map1 = list.get(i);
            newsBean.newsIconUrl = map1.get("user_touxiangURL").toString();
            newsBean.newTitle = map1.get("username").toString();
            newsBean.newsContent = map1.get("user_qianming").toString();
            newsBean.newsJifen = map1.get("user_jifen").toString();
            newsBeanList.add(newsBean);
        }
        return newsBeanList;    
    }

    /**
     * 实现网络的异步访问
     * @author Lenovo
     *
     */
    class NewsAsynkTask extends AsyncTask<Integer,Void, List<FenleiBean>>{

        @Override
        protected List<FenleiBean> doInBackground(Integer... params) {
            return getJsonData(params[0]);
        }

        @Override
        protected void onPostExecute(List<FenleiBean> newsBeans) {
            // TODO Auto-generated method stub
            super.onPostExecute(newsBeans);
            if(adapter == null){
                adapter = new FenleiAdapter(FenleiActivity.this, newsBeans);
                mListView.setAdapter(adapter);
            }else {
                adapter.onDateChange(newsBeans);
            }

            mListView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // TODO Auto-generated method stub
                    HashMap<String, Object> map1 = list.get(position);
                    Intent intent=new Intent();
                    intent.setClass(FenleiActivity.this,ChatOtoActivity.class);
                    intent.putExtra("username", map1.get("username").toString());     //用户名传到另一个界面
                    System.out.println("username"+map1.get("username").toString());
                    intent.putExtra("touxiang", map1.get("user_touxiangURL").toString());    //头像地址
                    //启动
                    startActivity(intent);

                    //Toast.makeText(FenleiActivity.this, "点击了"+newsBean.get("username"),Toast.LENGTH_SHORT).show();
                }
            });
        }


    }

    /**
     * 查询用户分类信息函数,放入list中,通过关键字key来取出
     * */

    public void searchTop10(int number)
    {
        //命名空间
        String nameSpace = "http://wsServer.gnuhpc.org/";
        //方法名字
        String methodName = "SearchTeacherTop10";
        // endPoint
        String endPoint =  "http://10.0.2.2:8080/wsServerHello";
        //soapAction
        String soapAction = "http://wsServer.gnuhpc.org/SearchTeacherTop10";
        //指定调用方法命名空间和方法名字
        SoapObject rpc = new SoapObject(nameSpace, methodName); 
        //调用方法时需要传入一个参数
        //为了与web service保持一致,需要设置为arg0,因为web service会自动将其转化为arg0 arg1
        rpc.addProperty("arg0",user_fenlei);
        rpc.addProperty("arg1",number);
        try {
            //wsdl地址
            HttpTransportSE transport = new HttpTransportSE(endPoint);
            transport.debug= true;
            //生成调用WebService方法的SOAP请求信息,并指定SOAP的版本 
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);    
            envelope.bodyOut = rpc;    
            //设置是否调用的是dotNet开发的WebService,服务器是.net的需要设置为true,java不用
            envelope.dotNet = false;                 
            envelope.setOutputSoapObject(rpc);                 

            System.out.println("rpc:"+rpc); 
            System.out.println("enevlope:"+envelope); 
            System.out.println("---基本服务设置完毕,下面开始调用服务");

            Log.v("---调用消息:", "开始call函数");
            transport.call(soapAction, envelope);
            Log.v("---函数结果:", ""+envelope.getResponse());
            if(envelope.getResponse()!=null)  
            {
                // 获取返回的数据  
                SoapObject object = (SoapObject) envelope.bodyIn; 
                System.out.println("---object:"+object);
                System.out.println("---获取数据成功!");
                System.out.println("object.toString():"+object.toString()); 

                // 获取返回的结果 ,将结果存入到一个Map中
                System.out.println(object.getProperty(0)); 
                int count = object.getPropertyCount();
                System.out.println("#######################"+count);

                for(int index = 0; index < count; index = index + 5)  //表中有五个关键字,循环条件+5
                {
                    map = new HashMap<String, Object>();
                    map.put("username", object.getProperty(index).toString());  //用户名
                    map.put("user_fenlei", object.getProperty(index+1).toString());  //分类
                    map.put("user_qianming", object.getProperty(index+2).toString());  //签名
                    map.put("user_touxiangURL", object.getProperty(index+3).toString());  //在线状态
                    map.put("user_jifen", object.getProperty(index+4).toString());  //积分
                    list.add(map);
                }
                System.out.println("list的值为:"+list);
            }
            else{
                Log.v("----连接消息:", "连接失败");
            }
        } catch (SoapFault e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void onl oad() {
        //获取更多数据
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                number=number+2;  //每次多显示两条数据
                new NewsAsynkTask().execute(number);
                //通知listView显示更新,加载完毕 
                
                /**
                 * 设置默认显示为Listview最后一行
                 */
                mListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
                mListView.setStackFromBottom(true);
                //通知listView加载完毕,底部布局消失
                mListView.loadComplete();

            }
        }, 1000);
    }

}
复制代码
package com.tdyl.consult.fenlei;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.tdyl.consult.R;
import com.tdyl.consult.fenlei.LoadListView.ILoadListener2;
import com.tdyl.consult.otochat.ChatOtoActivity;

public class FenleiActivity extends Activity implements ILoadListener2 {

    private LoadListView mListView;
    private String user_fenlei = "";
    private TextView title_name;
    int number = 10;
    FenleiAdapter adapter = null;

    ArrayList <HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();  //用来存放用户信息
    HashMap<String, Object> map = new HashMap<String, Object>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_fenlei);
        title_name = (TextView) findViewById(R.id.id_top_fenlei);
        mListView = (LoadListView) findViewById(R.id.lv_main);
        mListView.setInterface(this);
        Intent intent = getIntent();
        user_fenlei = intent.getStringExtra("user_fenlei");
        //-----------------------------------------------------------------------------
        title_name.setText(user_fenlei+"专家");
        new NewsAsynkTask().execute(number);
    }

    /**
     * 将url对应的json格式数据转化为我们缩封装的NewsBean对象
     * @param url
     * @return
     */
    private List<FenleiBean> getJsonData(int number){
        List<FenleiBean> newsBeanList = new ArrayList<FenleiBean>();
        //-----------------------------------------------------------------------------
        searchTop10(number);
        FenleiBean newsBean;
        if(list.size() == 0)
        {
            new AlertDialog.Builder(this)
            .setIcon(R.drawable.icon_menu)
            .setTitle("温馨小提示")
            .setMessage("没有要搜寻的专家分类")
            .setPositiveButton("立刻返回搜索界面...", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    finish();
                }
            }).show();
        }
        for(int i=0;i<list.size();i++)
        {
            newsBean = new FenleiBean();
            HashMap<String, Object> map1 = new HashMap<String, Object>();
            map1 = list.get(i);
            newsBean.newsIconUrl = map1.get("user_touxiangURL").toString();
            newsBean.newTitle = map1.get("username").toString();
            newsBean.newsContent = map1.get("user_qianming").toString();
            newsBean.newsJifen = map1.get("user_jifen").toString();
            newsBeanList.add(newsBean);
        }
        return newsBeanList;    
    }

    /**
     * 实现网络的异步访问
     * @author Lenovo
     *
     */
    class NewsAsynkTask extends AsyncTask<Integer,Void, List<FenleiBean>>{

        @Override
        protected List<FenleiBean> doInBackground(Integer... params) {
            return getJsonData(params[0]);
        }

        @Override
        protected void onPostExecute(List<FenleiBean> newsBeans) {
            // TODO Auto-generated method stub
            super.onPostExecute(newsBeans);
            if(adapter == null){
                adapter = new FenleiAdapter(FenleiActivity.this, newsBeans);
                mListView.setAdapter(adapter);
            }else {
                adapter.onDateChange(newsBeans);
            }

            mListView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // TODO Auto-generated method stub
                    HashMap<String, Object> map1 = list.get(position);
                    Intent intent=new Intent();
                    intent.setClass(FenleiActivity.this,ChatOtoActivity.class);
                    intent.putExtra("username", map1.get("username").toString());     //用户名传到另一个界面
                    System.out.println("username"+map1.get("username").toString());
                    intent.putExtra("touxiang", map1.get("user_touxiangURL").toString());    //头像地址
                    //启动
                    startActivity(intent);

                    //Toast.makeText(FenleiActivity.this, "点击了"+newsBean.get("username"),Toast.LENGTH_SHORT).show();
                }
            });
        }


    }

    /**
     * 查询用户分类信息函数,放入list中,通过关键字key来取出
     * */

    public void searchTop10(int number)
    {
        //命名空间
        String nameSpace = "http://wsServer.gnuhpc.org/";
        //方法名字
        String methodName = "SearchTeacherTop10";
        // endPoint
        String endPoint =  "http://10.0.2.2:8080/wsServerHello";
        //soapAction
        String soapAction = "http://wsServer.gnuhpc.org/SearchTeacherTop10";
        //指定调用方法命名空间和方法名字
        SoapObject rpc = new SoapObject(nameSpace, methodName); 
        //调用方法时需要传入一个参数
        //为了与web service保持一致,需要设置为arg0,因为web service会自动将其转化为arg0 arg1
        rpc.addProperty("arg0",user_fenlei);
        rpc.addProperty("arg1",number);
        try {
            //wsdl地址
            HttpTransportSE transport = new HttpTransportSE(endPoint);
            transport.debug= true;
            //生成调用WebService方法的SOAP请求信息,并指定SOAP的版本 
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);    
            envelope.bodyOut = rpc;    
            //设置是否调用的是dotNet开发的WebService,服务器是.net的需要设置为true,java不用
            envelope.dotNet = false;                 
            envelope.setOutputSoapObject(rpc);                 

            System.out.println("rpc:"+rpc); 
            System.out.println("enevlope:"+envelope); 
            System.out.println("---基本服务设置完毕,下面开始调用服务");

            Log.v("---调用消息:", "开始call函数");
            transport.call(soapAction, envelope);
            Log.v("---函数结果:", ""+envelope.getResponse());
            if(envelope.getResponse()!=null)  
            {
                // 获取返回的数据  
                SoapObject object = (SoapObject) envelope.bodyIn; 
                System.out.println("---object:"+object);
                System.out.println("---获取数据成功!");
                System.out.println("object.toString():"+object.toString()); 

                // 获取返回的结果 ,将结果存入到一个Map中
                System.out.println(object.getProperty(0)); 
                int count = object.getPropertyCount();
                System.out.println("#######################"+count);

                for(int index = 0; index < count; index = index + 5)  //表中有五个关键字,循环条件+5
                {
                    map = new HashMap<String, Object>();
                    map.put("username", object.getProperty(index).toString());  //用户名
                    map.put("user_fenlei", object.getProperty(index+1).toString());  //分类
                    map.put("user_qianming", object.getProperty(index+2).toString());  //签名
                    map.put("user_touxiangURL", object.getProperty(index+3).toString());  //在线状态
                    map.put("user_jifen", object.getProperty(index+4).toString());  //积分
                    list.add(map);
                }
                System.out.println("list的值为:"+list);
            }
            else{
                Log.v("----连接消息:", "连接失败");
            }
        } catch (SoapFault e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void onl oad() {
        //获取更多数据
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                number=number+2;  //每次多显示两条数据
                new NewsAsynkTask().execute(number);
                //通知listView显示更新,加载完毕 
                
                /**
                 * 设置默认显示为Listview最后一行
                 */
                mListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
                mListView.setStackFromBottom(true);
                //通知listView加载完毕,底部布局消失
                mListView.loadComplete();

            }
        }, 1000);
    }

}
复制代码

  感谢这门视频课程,汲取营养,继续努力......

标签:int,public,context,new,import,Android,ListView,android,加载
From: https://www.cnblogs.com/Alex80/p/17998149

相关文章

  • android 框架搭建
    1.下载androidstdio工具:如下:![image.png](/img/bVc2Mvo)2.下载对应的SDKtools.最好下载SDKzip.访问地址:https://www.androiddevtools.cn/![image.png](/img/bVc2Mvp)3.选择SDKpath.将解压后的目录进行选择。删除原下载文件。![image.png](/img/bVc2Mvl), 4.下载工程导入,这......
  • 在@KafkaListener启动之前需要做数据的预加载,该在Spring生命周期的哪个阶段做这个事情
    背景说明1、在Spring中消费Kafka数据时,最便捷的方法就是给方法加@KafkaListener注解。在数据消费逻辑中,需要先把一些配置信息预加载到内存中。有同事就提了一个问题:如果保证在消费者执行前,预加载数据的代码一定能执行完?也就是说,要等待数据预加载完成之后,再执行消费逻辑。大部分......
  • Android开发笔记[8]-基于Compose布局的开屏页
    摘要基于Compose布局的开屏页,显示进度条;自动跳转到其他页面.关键信息AndroidStudio:ElectricEel|2022.1.1Patch2Gradle:distributionUrl=https://services.gradle.org/distributions/gradle-7.5-bin.zipjvmTarget='1.8'minSdk21targetSdk33compileSdk33开......
  • Android原生定位
    使用LocationManager和LocationListener结合进行简单定位功能1.创建LocationManagerLocationManagerlocationManager=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);2.创建LocationListenerprivatefinalLocationListenerlocationListener=newLocati......
  • AndroidStudio-创建Kotlin匿名内部类时自动补全
    AndroidStudio-创建Kotlin匿名内部类时自动补全用Kotlin写代码,当要创建匿名类实例时,总是要自己手敲出来,不像Java一样,输入new就会有代码提示出来,去网上搜索,大部分都是AndroidStudio按住ctrl+空格键,或者ctrl+alt+空格会出现代码提示,我试了,嗯...好像啥反应也没有,然后发现每次按,输入......
  • [转]解决Visual Studio 调试时加载符号慢的问题 - zhaotianff - 博客园
    什么是调试符号编译程序时生成的一组特殊字符,并包含有关变量和函数在生成的二进制文件中的位置以及其他服务信息的信息。该数据集可用于逐步调试程序或检查第三方代码。调试符号可以添加到可执行文件或库中,但是大多数现代编译器将它们存储为单独的对象。例如,VisualStudio将调......
  • Xamarin.Android中使用TaskCompletionSource创建阻塞式的对话框
    代码如下usingAndroid.OS;usingAndroid.Views;usingAndroid.Util;usingActivity=Android.App.Activity;namespaceKangHuiXinCai_FangDai_AndroidScanner{publicclassDialog_SettingPassword:Dialog{TaskCompletionSource<DialogResu......
  • Pdfium.Net.Free 一个免费的Pdfium的 .net包装器--加载字体
    项目地址:Pdfium.Net:https://github.com/1000374/Pdfium.NetPdfiumViewer:https://github.com/1000374/PdfiumViewerPdfium.Net加载字体:1.加载ttf字体文件using(vardoc=PdfDocument.CreateNew()){varfontPath=@"c:\Windows\fonts\simhei.ttf";......
  • 未能加载文件或程序集或它的某一个依赖项
    https://jingyan.baidu.com/article/9f63fb916591e7c8400f0efe.html1、输入win+r,在弹出的输入框中输入inetmgr,快速打开iis2、点击应用程序池,可查看所有程序池 3、选中本项目使用的程序池,右键选择高级设置 4、看到启用32位应用程序位置为false 5、修改为true,保存。 ......
  • Android Studio如何解决Connect time out问题
    Hello各位同学们好,我是咕噜铁蛋,使用AndroidStudio是我们日常开发工作中不可缺少的工具。然而,在使用AndroidStudio进行开发时,有些时候会遇到连接超时(Connecttimeout)的问题,这会影响我们的开发进程,甚至可能导致应用无法正常运行。那么,如何解决这个问题呢?今天就由铁蛋来为大家介绍......