ViewList

今天才知道,昨天一个想法错了,之前以为一个活动只有一个布局,没想到还有嵌套的子布局

数组数据要通过适配器,由构造函数把数据传入,Java这个部分的知识还没学到,现在不清楚

学习的进度太慢了,很多要学的,失落但是还是要试试

这里包含两个效果,简单的文本数组数据显示是注释掉的

1.布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id = "@+id/view"
        >
    </ListView>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<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">

    <ImageView
        android:id = "@+id/image_anim"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:id = "@+id/anim_name"
        android:layout_gravity="center"
        android:layout_marginLeft="10dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
<pre name="code" class="html">    <EditText
        android:id = "@+id/infor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "type"/>
    <Button
        android:id = "@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text = "list"
        android:onClick="viewlistsend"/>


 

2.类

package com.example.a111.one;

/**
 * Created by 111 on 2016/5/31.
 */
public class ABCD {
    private String name;
    private int manageid;
    public ABCD(String na,int id){
        name = na;
        manageid = id;
    }
    public String getName(){
        return name;
    }
    public int getManageid(){
        return manageid;
    }
}
import java.util.List;

/**
 * Created by 111 on 2016/5/31.
 */
public class ABCDAdapter extends ArrayAdapter<ABCD>{
    private int resourceid;
    public ABCDAdapter(Context context, int textViewResourceId, List<ABCD> objects){
        super(context,textViewResourceId,objects);
        resourceid = textViewResourceId;
    }
    public View getView(int position, View convertView, ViewGroup parent){
        ABCD abcd = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceid,null);

        ImageView imageView = (ImageView)view.findViewById(R.id.image_anim);
        TextView textView = (TextView)view.findViewById(R.id.anim_name);
        imageView.setImageResource(abcd.getManageid());
        textView.setText(abcd.getName());

        return view;
    }
}

3.活动

public class ActivityC extends AppCompatActivity {


    private EditText inform;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity_c);
        inform = (EditText) findViewById(R.id.infor);
        Intent intent = getIntent();

        /*Bundle data = intent.getBundleExtra("data");
        String in_data = data.getString("infor");*/

        String in_data = intent.getStringExtra("infor");
        inform.setText(in_data);
    }
    public void viewlistsend(View view){
        Intent viewlist = new Intent(this,Activity_viewlist.class);
        startActivity(viewlist);
    }
}
package com.example.a111.one;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class Activity_viewlist extends AppCompatActivity {

    //private String []data = {"AAA","BBB","CCC","DDD","EEE","FFF","GGG","HHH","LLL","JJJ",
          //  "KKK","MMM","NNN","WWW","RRR","YYY","TTT","QQQ"};
    private List<ABCD> animlist = new ArrayList<ABCD>();

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view);

        //ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data);
        //ListView listView = (ListView) findViewById(R.id.view);
        //listView.setAdapter(adapter);

        initanim();
        ABCDAdapter abcdAdapter = new ABCDAdapter(this,R.layout.activity_activity_viewlist,animlist);
        ListView listView = (ListView) findViewById(R.id.view);
        listView.setAdapter(abcdAdapter);
    }
    private void initanim(){

        ABCD a = new ABCD("AAA",R.drawable.d);
        animlist.add(a);
        ABCD b = new ABCD("BBB",R.drawable.d);
        animlist.add(b);
        ABCD c = new ABCD("CCC",R.drawable.d);
        animlist.add(c);
        ABCD d = new ABCD("DDD",R.drawable.d);
        animlist.add(d);
        ABCD e = new ABCD("EEE",R.drawable.e);
        animlist.add(e);
        ABCD f = new ABCD("RRR",R.drawable.d);
        animlist.add(f);
        ABCD g = new ABCD("TTT",R.drawable.d);
        animlist.add(g);
        ABCD q = new ABCD("YYY",R.drawable.d);
        animlist.add(q);
        ABCD r = new ABCD("UUU",R.drawable.d);
        animlist.add(r);
        ABCD t = new ABCD("OOO",R.drawable.e);
        animlist.add(t);
        ABCD y = new ABCD("QQQ",R.drawable.d);
        animlist.add(y);
        ABCD h = new ABCD("SSS",R.drawable.d);
        animlist.add(h);
        ABCD m = new ABCD("ZZZ",R.drawable.d);
        animlist.add(m);
        ABCD n = new ABCD("KKK",R.drawable.d);
        animlist.add(n);
    }
}

4.结果



给这个方法添加单元测试: public List<MessageDetails> processTrade(CisTStpTradeData tradeData) throws CisTStpException { List<T> viewList = getTradeData(tradeData.getTradeId()); log.info("Size of Object fetched for CIS Trade id {} is {} ", tradeData.getTradeId(), viewList.size()); if(!validateRequest(viewList)){ log.info("Not a valid data to process...."); return null; } Map<String, List<T>> viewAsMap = getViewAsMap(viewList); List<MessageDetails> msgDetailsListAllLegs = new ArrayList<>(); /Process REPO Leg first/ CisRefScbmlEvents reUseRefEvent = null; if(viewAsMap != null && viewAsMap.size() > 0 && viewAsMap.containsKey(TradeLegs.REPO_LEG.getValue())){ log.info("REPO Leg identified in the package"); Map<String, List<T>> repoViewAsMap = viewAsMap.entrySet().stream().filter(p -> p.getKey().equals(TradeLegs.REPO_LEG.getValue())).collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue())); processAllMsgDetail(repoViewAsMap, tradeData, msgDetailsListAllLegs, null); log.info("Event will be reused for other LEGS in package"); if(msgDetailsListAllLegs != null && msgDetailsListAllLegs.size() > 0 && msgDetailsListAllLegs.get(0).getEventDetails() != null){ reUseRefEvent = msgDetailsListAllLegs.get(0).getEventDetails().getRefEvent(); log.info("REPO Event to be reused for other legs is : {} ", reUseRefEvent); } log.info("REPO Leg processed and removed from Map"); viewAsMap.remove(TradeLegs.REPO_LEG.getValue()); } /*Process SCF leg */ if(viewAsMap != null && viewAsMap.size() > 0 && viewAsMap.containsKey(TradeLegs.SCF_LEG.getValue())){ log.info("SCF Leg identified in the package"); Map<String, List<T>> repoViewAsMap = viewAsMap.entrySet().stream().filter(p -> p.getKey().equals(TradeLegs.SCF_LEG.getValue())).collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue())); processAllMsgDetail(repoViewAsMap, tradeData, msgDetailsListAllLegs, null); log.info("SCF Leg processed and removed from Map"); viewAsMap.remove(TradeLegs.SCF_LEG.getValue()); } /Process NON REPO and other CIS and SIP Legs After it. This is done to reuse the Event identified for REPO above for same package/ processAllMsgDetail(viewAsMap, tradeData, msgDetailsListAllLegs, reUseRefEvent); return msgDetailsListAllLegs; }
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值