1

I'm new to the android world. I have a xml layout that i want to add as child to other xml file's scrollview.

This is the layout[ offerview.xml ] to be inserted multiple times is -

enter image description here

The xml[activity_offer.xml] into which it has to be inserted is -

enter image description here

Java Code of the activity is -

public class OfferActivity extends Activity {

private static final String name = "Reebok";
private static final String content = "50% off on Reebok Shoes at Reliance Mart";

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

    View v = LayoutInflater.from(getApplicationContext()).inflate(R.layout.offerview, null);

    TextView offerItemTextView = (TextView) v.findViewById(R.id.offerItemTextView);
    offerItemTextView.setText(name);

    TextView offerContentTextView = (TextView) v.findViewById(R.id.offertextView);
    offerContentTextView.setText(content);

    ImageView offerImage = (ImageView) v.findViewById(R.id.offerImageView);
    offerImage.setBackgroundResource(R.drawable.ps);

    ((LinearLayout) findViewById(R.id.offersLayout)).addView(v);


    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.offer, menu);
    return true;
}

}

At the moment i was just trying to include view only one time. The app crashed.

enter image description here

enter image description here

I've been stuck forever on this.

2 Answers 2

1

You are missing layout_width and layout_height in your offersLayout

...
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/offersLayout">
</LinearLayout>
...
Sign up to request clarification or add additional context in comments.

Comments

1

Log file say that you must add layout_width atts of LinerLayout in activity_offer.xml. You can using merge tag to using again xml file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.