代码覆盖从Strings.xml

时间:2018-04-30 22:41:23

标签: java android layout overwrite expandable

我正在创建一个具有标题和子项的可扩展布局。我将信息传递给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;
    }
}

0 个答案:

没有答案