Skip to main content
Tweeted twitter.com/StackOverflowPT/status/1297685094581383168
replaced http://pt.stackoverflow.com/ with https://pt.stackoverflow.com/
Fonte Link

Melhoria para esta questão, que eu mesmo coloquei: Como preencher setText do TextView a partir de um ArrayList?

Melhoria para esta questão, que eu mesmo coloquei: Como preencher setText do TextView a partir de um ArrayList?

conteúdo editado; título editado
Fonte Link
viana
  • 27,7mil
  • 26
  • 96
  • 198

Criar textviewsTextView's dinamicamente na tela

Tenho um textViewTextView e gostaria que, em vez do preenchimento com um arraylistArraylist, com todos os itens em seu setText, que ele fosse criado várias vezes na tela, com os respectivos itens deste array, em cada setText de cada textViewTextView.

Criar textviews dinamicamente na tela

Tenho um textView e gostaria que, em vez do preenchimento com um arraylist, com todos os itens em seu setText, que ele fosse criado várias vezes na tela, com os respectivos itens deste array, em cada setText de cada textView.

Criar TextView's dinamicamente

Tenho um TextView e gostaria que, em vez do preenchimento com um Arraylist, com todos os itens em seu setText, que ele fosse criado várias vezes na tela, com os respectivos itens deste array, em cada setText de cada TextView.

adicionou 598 caracteres ao conteúdo
Fonte Link

Tenho um textView e gostaria que, em vez do preenchimento com um arraylist, com todos os itens em seu setText, que ele fosse criado várias vezes na tela, com os respectivos itens deste array, em cada setText de cada textView. Segue o código:

public class RideRequestActivity extends AppCompatActivity implements CommunityRequestView {Segue o código:

public class RideRequestActivity extends AppCompatActivity implements CommunityRequestView {

    private SessionManager user;
    private String departure;
    private String arrival;



    @BindView(R.id.request_email)
    TextView email;


    @BindView(R.id.request_name)
    TextView name;


    @BindView(R.id.request_photo)
    ImageView photo;


    @BindView(R.id.textView_first)
    TextView first;

    @BindView(R.id.textView_second)
    TextView second;

    @BindView(R.id.textView_third)
    TextView third;

    @BindView(R.id.button0)
    CheckBox button0;

    @BindView(R.id.button1)
    CheckBox button1;

    @BindView(R.id.button2)
    CheckBox button2;

    @BindView(R.id.button3)
    CheckBox button3;

    @BindView(R.id.button4)
    CheckBox button4;

    @BindView(R.id.button5)
    CheckBox button5;

    @BindView(R.id.send_offer_request)
    Button send_offer_request;

    @BindView(R.id.send_ask_request)
    Button send_ask_request;

    @BindView(R.id.txtInterests)
    TextView mListView;

    @BindView(R.id.img_favorite)
    ImageView imgFavorite;

    CommunityPresenter presenter;
    UserCommunity selectedUser;
    UsersMySQLiteHelper serviceDB;
    private List<UserCommunity> userInterest = new ArrayList<UserCommunity>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setEnterTransition(new Fade());
        }
        setContentView(R.layout.activity_ride_request);
        serviceDB = new UsersMySQLiteHelper(AppController.getInstance().getApplicationContext());

        ButterKnife.bind(this);
        presenter = new CommunityPresenter(this);


        first.setText(presenter.getDay(0));
        second.setText(presenter.getDay(1));
        third.setText(presenter.getDay(2));

        user = new SessionManager();

        selectedUser = CommunityService.i(getContext()).selectedUser;
        reloadView();

        send_offer_request.setOnClickListener(presenter.sendRequestOnClickListener(0));
        send_ask_request.setOnClickListener(presenter.sendRequestOnClickListener(1));
        imgFavorite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(selectedUser.favorite == 0) {
                    selectedUser.favorite = 1;
                    imgFavorite.setImageResource(R.drawable.ic_star_black_on_48px);
                }else{
                    selectedUser.favorite = 0;
                    imgFavorite.setImageResource(R.drawable.ic_star_border_black_off_48px);
                }
                selectedUser.save(serviceDB, user.getLoggedUser().getCompany());
            }
        });

        populateInterests();
        getPoints();

        imgFavorite = (ImageView)findViewById(R.id.img_favorite);
        if (selectedUser.favorite == 0){
            imgFavorite.setImageResource(R.drawable.ic_star_border_black_off_48px);
        }else{
            imgFavorite.setImageResource(R.drawable.ic_star_black_on_48px);
        }




    }

    private void getPoints() {
    }

    private void populateInterests() {
        RequestManager.UsersInterests(selectedUser.id, new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String result) {
                if(e== null || result != null) {
                    UserCommunity user = new Gson().fromJson(new JsonParser().parse(result).getAsJsonObject().get("data").toString(),
                            UserCommunity.class);

                    selectedUser.interests = user.interests;
                    String name = "";
                    TextView txt_Interests = (TextView) findViewById(R.id.txtInterests);
                    for (UserCommunity.Interest interest: selectedUser.interests
                         ) {
                           name += interest.name + " ";
                           txt_Interests.setText(name);
                    }
                    String point = "";
                    TextView points = (TextView)findViewById(R.id.txt_Points);
                    selectedUser.points = user.points;
                    point = selectedUser.points + "\npontos";
                    points.setText(point);

                }
            }
        });

    }

Tenho um textView e gostaria que, em vez do preenchimento com um arraylist, com todos os itens em seu setText, que ele fosse criado várias vezes na tela, com os respectivos itens deste array, em cada setText de cada textView. Segue o código:

public class RideRequestActivity extends AppCompatActivity implements CommunityRequestView {

private SessionManager user;
private String departure;
private String arrival;



@BindView(R.id.request_email)
TextView email;


@BindView(R.id.request_name)
TextView name;


@BindView(R.id.request_photo)
ImageView photo;


@BindView(R.id.textView_first)
TextView first;

@BindView(R.id.textView_second)
TextView second;

@BindView(R.id.textView_third)
TextView third;

@BindView(R.id.button0)
CheckBox button0;

@BindView(R.id.button1)
CheckBox button1;

@BindView(R.id.button2)
CheckBox button2;

@BindView(R.id.button3)
CheckBox button3;

@BindView(R.id.button4)
CheckBox button4;

@BindView(R.id.button5)
CheckBox button5;

@BindView(R.id.send_offer_request)
Button send_offer_request;

@BindView(R.id.send_ask_request)
Button send_ask_request;

@BindView(R.id.txtInterests)
TextView mListView;

@BindView(R.id.img_favorite)
ImageView imgFavorite;

CommunityPresenter presenter;
UserCommunity selectedUser;
UsersMySQLiteHelper serviceDB;
private List<UserCommunity> userInterest = new ArrayList<UserCommunity>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setEnterTransition(new Fade());
    }
    setContentView(R.layout.activity_ride_request);
    serviceDB = new UsersMySQLiteHelper(AppController.getInstance().getApplicationContext());

    ButterKnife.bind(this);
    presenter = new CommunityPresenter(this);


    first.setText(presenter.getDay(0));
    second.setText(presenter.getDay(1));
    third.setText(presenter.getDay(2));

    user = new SessionManager();

    selectedUser = CommunityService.i(getContext()).selectedUser;
    reloadView();

    send_offer_request.setOnClickListener(presenter.sendRequestOnClickListener(0));
    send_ask_request.setOnClickListener(presenter.sendRequestOnClickListener(1));
    imgFavorite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(selectedUser.favorite == 0) {
                selectedUser.favorite = 1;
                imgFavorite.setImageResource(R.drawable.ic_star_black_on_48px);
            }else{
                selectedUser.favorite = 0;
                imgFavorite.setImageResource(R.drawable.ic_star_border_black_off_48px);
            }
            selectedUser.save(serviceDB, user.getLoggedUser().getCompany());
        }
    });

    populateInterests();
    getPoints();

    imgFavorite = (ImageView)findViewById(R.id.img_favorite);
    if (selectedUser.favorite == 0){
        imgFavorite.setImageResource(R.drawable.ic_star_border_black_off_48px);
    }else{
        imgFavorite.setImageResource(R.drawable.ic_star_black_on_48px);
    }




}

private void getPoints() {
}

private void populateInterests() {
    RequestManager.UsersInterests(selectedUser.id, new FutureCallback<String>() {
        @Override
        public void onCompleted(Exception e, String result) {
            if(e== null || result != null) {
                UserCommunity user = new Gson().fromJson(new JsonParser().parse(result).getAsJsonObject().get("data").toString(),
                        UserCommunity.class);

                selectedUser.interests = user.interests;
                String name = "";
                TextView txt_Interests = (TextView) findViewById(R.id.txtInterests);
                for (UserCommunity.Interest interest: selectedUser.interests
                     ) {
                       name += interest.name + " ";
                       txt_Interests.setText(name);
                }
                String point = "";
                TextView points = (TextView)findViewById(R.id.txt_Points);
                selectedUser.points = user.points;
                point = selectedUser.points + "\npontos";
                points.setText(point);

            }
        }
    });

}

Tenho um textView e gostaria que, em vez do preenchimento com um arraylist, com todos os itens em seu setText, que ele fosse criado várias vezes na tela, com os respectivos itens deste array, em cada setText de cada textView.

Segue o código:

public class RideRequestActivity extends AppCompatActivity implements CommunityRequestView {

    private SessionManager user;
    private String departure;
    private String arrival;



    @BindView(R.id.request_email)
    TextView email;


    @BindView(R.id.request_name)
    TextView name;


    @BindView(R.id.request_photo)
    ImageView photo;


    @BindView(R.id.textView_first)
    TextView first;

    @BindView(R.id.textView_second)
    TextView second;

    @BindView(R.id.textView_third)
    TextView third;

    @BindView(R.id.button0)
    CheckBox button0;

    @BindView(R.id.button1)
    CheckBox button1;

    @BindView(R.id.button2)
    CheckBox button2;

    @BindView(R.id.button3)
    CheckBox button3;

    @BindView(R.id.button4)
    CheckBox button4;

    @BindView(R.id.button5)
    CheckBox button5;

    @BindView(R.id.send_offer_request)
    Button send_offer_request;

    @BindView(R.id.send_ask_request)
    Button send_ask_request;

    @BindView(R.id.txtInterests)
    TextView mListView;

    @BindView(R.id.img_favorite)
    ImageView imgFavorite;

    CommunityPresenter presenter;
    UserCommunity selectedUser;
    UsersMySQLiteHelper serviceDB;
    private List<UserCommunity> userInterest = new ArrayList<UserCommunity>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setEnterTransition(new Fade());
        }
        setContentView(R.layout.activity_ride_request);
        serviceDB = new UsersMySQLiteHelper(AppController.getInstance().getApplicationContext());

        ButterKnife.bind(this);
        presenter = new CommunityPresenter(this);


        first.setText(presenter.getDay(0));
        second.setText(presenter.getDay(1));
        third.setText(presenter.getDay(2));

        user = new SessionManager();

        selectedUser = CommunityService.i(getContext()).selectedUser;
        reloadView();

        send_offer_request.setOnClickListener(presenter.sendRequestOnClickListener(0));
        send_ask_request.setOnClickListener(presenter.sendRequestOnClickListener(1));
        imgFavorite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(selectedUser.favorite == 0) {
                    selectedUser.favorite = 1;
                    imgFavorite.setImageResource(R.drawable.ic_star_black_on_48px);
                }else{
                    selectedUser.favorite = 0;
                    imgFavorite.setImageResource(R.drawable.ic_star_border_black_off_48px);
                }
                selectedUser.save(serviceDB, user.getLoggedUser().getCompany());
            }
        });

        populateInterests();
        getPoints();

        imgFavorite = (ImageView)findViewById(R.id.img_favorite);
        if (selectedUser.favorite == 0){
            imgFavorite.setImageResource(R.drawable.ic_star_border_black_off_48px);
        }else{
            imgFavorite.setImageResource(R.drawable.ic_star_black_on_48px);
        }




    }

    private void getPoints() {
    }

    private void populateInterests() {
        RequestManager.UsersInterests(selectedUser.id, new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String result) {
                if(e== null || result != null) {
                    UserCommunity user = new Gson().fromJson(new JsonParser().parse(result).getAsJsonObject().get("data").toString(),
                            UserCommunity.class);

                    selectedUser.interests = user.interests;
                    String name = "";
                    TextView txt_Interests = (TextView) findViewById(R.id.txtInterests);
                    for (UserCommunity.Interest interest: selectedUser.interests
                         ) {
                           name += interest.name + " ";
                           txt_Interests.setText(name);
                    }
                    String point = "";
                    TextView points = (TextView)findViewById(R.id.txt_Points);
                    selectedUser.points = user.points;
                    point = selectedUser.points + "\npontos";
                    points.setText(point);

                }
            }
        });

    }
Fonte Link
Henrique
  • 1mil
  • 13
  • 34
Carregando