通过xml配置的回溯列表属性

时间:2016-02-13 21:34:14

标签: java logging logback

我正在编写自己的布局,我希望能够从配置文件中传递值列表。

我的布局代码:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="rpost.MyPatternLayout">
                <pattern>%date{HH:mm:ss.SSS} [%t] %-5p %c{40}:%L - %m%n</pattern>
                <test>value 1</test>
                <test>value 2</test>
            </layout>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

配置:

{{1}}

上面的示例不起作用 - 它什么都不打印。

是否可以配置列表属性?怎么办呢?

1 个答案:

答案 0 :(得分:2)

我找到了以下解决方案:

配置(与问题相同):

public class requests extends DialogFragment implements AdapterView.OnItemClickListener {
ListView listView;
int id;
Communicator communicator;
ArrayList<Integer> intlist,picslist,phone,idlist;
ArrayList<String> plat,plang,dlat,dlang,r,a;
ArrayList<String> pickuplist,name;
ArrayList<String> destinationlist;
SwipeRefreshLayout refreshLayout;
Dialog dialog;
Adapter adapter;
@Override
public void onStart() {

    super.onStart();
    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    }
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

     dialog = super.onCreateDialog(savedInstanceState);
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    return dialog;

}
@Override
public void onAttach(Activity activity) {

    communicator= (Communicator) activity;

    super.onAttach(activity);
}

@Override
public void onCreate(Bundle savedInstanceState)

{


    super.onCreate(savedInstanceState);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


    View view = inflater.inflate(R.layout.requests, null);

    picslist = new ArrayList<>();
    intlist = new ArrayList<>();
    pickuplist = new ArrayList<>();
    destinationlist = new ArrayList<>();
    phone = new ArrayList<>();
    idlist = new ArrayList<>();
    plat = new ArrayList<>();
    plang = new ArrayList<>();
    plat = new ArrayList<>();
    plang = new ArrayList<>();
    dlat = new ArrayList<>();
    dlang = new ArrayList<>();
    r = new ArrayList<>();
    a = new ArrayList<>();




    intlist = getArguments().getIntegerArrayList("images");
    pickuplist = getArguments().getStringArrayList("pickup");
    destinationlist = getArguments().getStringArrayList("destination");
    name = getArguments().getStringArrayList("name");
    phone = getArguments().getIntegerArrayList("phone");
    idlist = getArguments().getIntegerArrayList("ids");
    plat = getArguments().getStringArrayList("plat");
    plang = getArguments().getStringArrayList("plang");
    dlat = getArguments().getStringArrayList("dlat");
    dlang = getArguments().getStringArrayList("dlang");
    a = getArguments().getStringArrayList("dlang");
    r = getArguments().getStringArrayList("dlang");
    for (Integer inty : intlist) {
        switch (inty) {
            case 0:
                picslist.add(R.drawable.man2);
                break;
            case 1:
                picslist.add(R.drawable.woman2);
                break;
            case 2:
                picslist.add(R.drawable.handicapped2);
                break;
            case 3:
                picslist.add(R.drawable.pregnant2);
                break;
            default:
                break;


        }

    }
    refreshLayout=(SwipeRefreshLayout)view.findViewById(R.id.swiperefresh);
            refreshLayout.setOnRefreshListener(
                    new SwipeRefreshLayout.OnRefreshListener() {
                        @Override
                        public void onRefresh() {
                                communicator.refresh();
                                dismiss();

                        }
                    }
            );

        listView = (ListView) view.findViewById(R.id.listView);

         adapter = new Adapter(getActivity(), pickuplist, destinationlist, picslist);

        listView.setAdapter(adapter);


        listView.setOnItemClickListener(this);
        return view;


    }





@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {



    if (position < name.size()&&position<plat.size()&&position<plang.size()&&position<dlat.size()&&position<dlang.size()&&position<intlist.size()&&position<idlist.size()&&position<phone.size()){

        Intent intent = new Intent(getActivity(), client.class);
        intent.putExtra("name", name.get(position));
    intent.putExtra("phone", phone.get(position));
    intent.putExtra("plat", plat.get(position).toString());
    intent.putExtra("plang", plang.get(position).toString());
    intent.putExtra("dlat", dlat.get(position).toString());
    intent.putExtra("dlang", dlang.get(position).toString());
    intent.putExtra("extra", intlist.get(position));
    intent.putExtra("id", idlist.get(position));
    getActivity().startActivity(intent);


}

}

class Adapter extends ArrayAdapter<String>{
    Context context;

    ArrayList<Integer> images=new ArrayList<>();
    ArrayList<String> pickup=new ArrayList<>();
    ArrayList<String> destination=new ArrayList<>();
    Adapter(Context c,ArrayList<String> pickup,ArrayList<String> destination, ArrayList<Integer> images) {
        super(c,R.layout.raw,R.id.textView,pickup);
        this.context=c;
        this.images=images;
        this.pickup=pickup;
        this.destination=destination;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View raw=convertView;

        if(raw==null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            raw = inflater.inflate(R.layout.requestsraw, parent, false);

        }

        ImageView imageView= (ImageView) raw.findViewById(R.id.imageView22);
        TextView pickupp=(TextView) raw.findViewById(R.id.textView15);
        TextView destinationn=(TextView) raw.findViewById(R.id.textView16);

        if(position<picslist.size()&&position<pickuplist.size()&&position<destinationlist.size()) {
            imageView.setImageResource(picslist.get(position));
            pickupp.setText(pickuplist.get(position));
            destinationn.setText(destinationlist.get(position));
        }


        return raw;

    }

}


}

Java代码:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="rpost.MyPatternLayout">
                <pattern>%date{HH:mm:ss.SSS} [%t] %-5p %c{40}:%L - %m%n</pattern>
                <test>value 1</test>
                <test>value 2</test>
            </layout>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>