Добавление непрерывного приращения для адаптера setText во время приращения адаптера просмотра списка - PullRequest
0 голосов
/ 21 мая 2019

Я пытаюсь получить значение приращения для адаптера просмотра текста во время приращения процесса для адаптера просмотра списка.

Я продолжаю получать только строки приращения для набора адаптеров просмотра списка, но без каких-либо изменений в адаптере просмотра текстазначение.

Если возможно, как вы получаете данные int x или счетчик циклов, сгенерированный из mainActivity, чтобы я мог использовать его для переменной в listoutput.java

Кто-нибудь знает, какрешить эту проблему?Я был неделю, и еще предстоит найти решение.

До сих пор я пытался поместить метод цикла в java listoutput для getYear и getTotal, чтобы tvyear и tvtoal.setText могли увеличиваться во время приращения процесса цикла просмотра списка, найденного в MainActivity..

Может работать, но отображается пустой экран.

MainActivity.java

package com.app.practiceincrement01;

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

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

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

        //Create the listoutput object
        //Try to create loop
        ArrayList<listoutput> computelist = new ArrayList<>();


        //looping increment for listview adapter
        for(int x = 0; x < 10 ; x++) {
               listoutput tablecompute = new listoutput(0, 0);
               computelist.add(tablecompute);
           }

        listoutputadapter adapter = new listoutputadapter(this, R.layout.adapter_view_layout, computelist);

        mlistView.setAdapter(adapter);


    }
}

listoutputadapter.java

package com.app.practiceincrement01;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

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

public class listoutputadapter extends ArrayAdapter<listoutput> {

    private static final String TAG ="PersonListAdapter";

    private Context mContext;
    int mResource;

    public listoutputadapter(Context context, int resource, ArrayList<listoutput> objects) {
        super(context, resource, objects);
        mContext = context;
        mResource = resource;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView,  ViewGroup parent) { //delete the super

            double year = getItem(position).getYear();
            String yearz = Double.toString(year);

            double total = getItem(position).getTotal();
            String totalz = Double.toString(total);

        //Create the person object with the information
        listoutput output = new listoutput(year,total);

        LayoutInflater inflater = LayoutInflater.from(mContext); //need to learn again
        convertView = inflater.inflate(mResource, parent,false);

        TextView tvyear = (TextView) convertView.findViewById(R.id.tvyear);
        TextView tvtotal = (TextView) convertView.findViewById(R.id.tvtotal);

        // How to create looping for tvyear.setText and tvtotal.setText during looping listview adapter?
        tvyear.setText(yearz);
        tvtotal.setText(totalz);

        return convertView;
    }
}

listoutput.java

package com.app.practiceincrement01;

public class listoutput {

    double year;
    double total;

    public double getYear() {

        int x = 10; // how to get the x data from the listoutputadapter?
        for (year = 0; year < x; year++){ //how to retrieve the data from listoutputadapter
            year = 0;
    }
            return year;

    }

    public void setYear(double year) {
        this.year = year;
    }

    public double getTotal() {
        int x = 10;
        for (total = 0; total < x; total++) { //how to retrieve the data from listoutputadapter
            total = 0;
        }
            return total;

    }

    public void setTotal(double total) {
        this.total = total;
    }

    public listoutput(double year, double total) {
        this.year = year;
        this.total = total;
    }
}


````
If the year number set to 1 and total number set to 2 for textview 1&2 respectively. For loop int x set to x=0;x<5;x++ in MainActivity.

Expected results would be
1       2
2       3
3       4
4       5
5       6
----------------------------------
Actual results is Blank screen + able to run without errors.
...