Код перезаписывает информацию, переданную из Strings.xml - PullRequest
0 голосов
/ 01 мая 2018

Я создаю расширяемый макет, который имеет заголовок и дочерний элемент. Я передаю информацию обоим с помощью strings.xml. Тем не менее, похоже, что мой сайт и номер телефона перезаписаны добавленным последним разделом. Например, я хочу, чтобы в первом разделе был файл activity1_website, но когда я добавил второй раздел, он переписал мой веб-сайт на activity2_website. Заранее спасибо за помощь.

public class ActivitiesActivity extends AppCompatActivity {

public int activity_name_int;
public int activity_phone_int;
public int activity_website_int;



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


    ExpandableLayout layout = (ExpandableLayout) findViewById(R.id.activities_expandable_layout);
    layout.setRenderer(new ExpandableLayout.Renderer<ActivitiesHeader, ActivitiesChild>() {
        @Override
        public void renderParent(View view, ActivitiesHeader activitiesHeader, boolean b, int i) {
            ((TextView) view.findViewById(R.id.activity_names)).setText(activitiesHeader.activity_name);
        }

        @Override
        public void renderChild(View view, ActivitiesChild activitiesChild, int i, int i1) {
            ((TextView) view.findViewById(R.id.textview_website)).setText(activitiesChild.website);

            ((TextView) view.findViewById(R.id.textview_website)).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Uri uri = Uri.parse(getResources().getString(activity_website_int)); // missing 'http://' will cause crashed
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                }
            });

            ((TextView) view.findViewById(R.id.textview_phone)).setText(activitiesChild.phone);
            ((TextView) view.findViewById(R.id.textview_phone)).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(ActivitiesActivity.this, activity_phone_int, Toast.LENGTH_SHORT).show();
                }
            });
        }
    });


    layout.addSection(getSection((R.string.activity1_name), (R.string.activity1_website), (R.string.activity1_phone_number)));
    layout.addSection(getSection((R.string.activity2_name), (R.string.activity2_website), (R.string.activity2_phone_number)));
}


// === Creates the List of Activities ===
private Section<ActivitiesHeader,ActivitiesChild> getSection(int name, int website, int phone) {
    activity_name_int = name;
    activity_website_int = website;
    activity_phone_int = phone;

    String activity_name = getResources().getString(activity_name_int);
    String activity_website = getResources().getString(activity_website_int);
    String activity_phone = getResources().getString(activity_phone_int);


    Section<ActivitiesHeader, ActivitiesChild> section = new Section<>();
    ActivitiesHeader activitiesHeader = new ActivitiesHeader(activity_name);


    List<ActivitiesChild> listActivities = new ArrayList<>();
    listActivities.add(new ActivitiesChild(activity_website,activity_phone));
    section.parent = activitiesHeader;
    section.children.addAll(listActivities);


    return section;
}
}

public class ActivitiesHeader {
public String activity_name;

    public ActivitiesHeader(String activity_name) {
        this.activity_name = activity_name;
    }
}

public class ActivitiesChild {
public String phone;
public String website;

public ActivitiesChild(String website, String phone) {
        this.phone = phone;
        this.website = website;
    }
}
...