Dynamic android layout background



I have this Fragment with ListView.


How to set the background to be the same as in the image uploaded in ImageView, so that I can fill dynamically every row with the same background of the image that is being pulled from the XML file. Url links of my images are located in my XML file, which I'm pulling with XML parser...


enter image description here


Currently I'm getting this white background(which I want to fill) with my layout from item_shadow.xml:



<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://ift.tt/nIICcg">
<item >
<shape
android:shape="rectangle">
<solid android:color="@android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>


ListView rows are filled with following:



<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/item_shadow"
android:padding="10dp" >

<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />

<ImageView
android:id="@+id/iconUrl"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" />

</RelativeLayout>


And this is my Fragment:



public class Preporuceno extends Fragment {

private AppAdapter mAdapter;
private ListView siteList;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.i("mobAppModel", "OnCreate()");
View rootView = inflater.inflate(R.layout.activity_preporuceno, container, false);


siteList = (ListView) rootView.findViewById(R.id.listView1);

siteList.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent, View v, int pos,long id) {
String url = mAdapter.getItem(pos).getstoreURL();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

}
});

if(isNetworkAvailable()){
Log.i("mobAppModel", "starting download Task");
AppDownloadTask download = new AppDownloadTask();
download.execute();
}else{
mAdapter = new AppAdapter(getActivity().getApplicationContext(), -1, XMLsourcePullParser.getmobAppModel(getActivity()));
siteList.setAdapter(mAdapter);
}

return rootView;
}

private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
private class AppDownloadTask extends AsyncTask<Void, Void, Void>{
@Override
protected Void doInBackground(Void... arg0) {
//Download the file
try {
Downloader.DownloadFromUrl("http://ift.tt/ULFcxd", getActivity().openFileOutput("XMLsource.xml", Context.MODE_PRIVATE));
} catch (FileNotFoundException e) {
e.printStackTrace();
}

return null;
}
@Override
protected void onPostExecute(Void result){
//setup our Adapter and set it to the ListView.
Activity attached = getActivity();
if (attached != null) {
mAdapter = new AppAdapter(getActivity().getApplicationContext(), -1, XMLsourcePullParser.getmobAppModel(getActivity()));

siteList.setAdapter(mAdapter);

Log.i("mobAppModel", "adapter size = "+ mAdapter.getCount());}
}

}

}

No comments:

Post a Comment