J'ai fait listview personnalisé dans l'activité android qui a progressbar. En plus de cette liste, il y a une autre barre de progression qui montre les progrès au fur et à mesure que le jour passe dans le mois. Maintenant, je veux définir une barre en fonction de la progression de la barre de progression du mois dans la liste personnalisée qui a quatre barres de progression. S'il vous plaît voir l'image ci-jointe.Comment ajouter une vue à la liste personnalisée dans Android?
Les progrès de la barre de progression du mois et la barre que nous mettons dans listview barre de progression devrait être à la même position signifie alignés et cette barre que nous mettons devrait se déplacer lorsque l'augmentation de progrès haut en passe jour.
Dans le fichier Layout j'ai utilisé LinearLayout là où je veux mettre la barre.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<RelativeLayout android:id="@+id/Top"
android:layout_centerHorizontal="true" android:layout_width="250dip"
android:layout_height="wrap_content">
<TextView android:id="@+id/LeftText" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="O"
android:textColor="#FFFFFF" android:textStyle="normal"
android:layout_alignParentLeft="true" />
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true">
<TextView android:id="@+id/TextOne" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="O"
android:textColor="#FFFFFF" android:textStyle="normal"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/TextTwo" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/outof"
android:textColor="#FFFFFF" android:textStyle="normal"
android:layout_toRightOf="@+id/TextOne" android:layout_marginRight="5dip" />
<TextView android:id="@+id/RightText" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="O"
android:textColor="#FFFFFF" android:textStyle="normal"
android:layout_toRightOf="@+id/TextTwo" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout android:id="@+id/Bottom"
android:layout_below="@+id/Top" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true">
<ProgressBar android:id="@+id/CustomPro"
android:layout_width="250dip" android:layout_height="wrap_content"
android:progress="0" android:max="100" android:secondaryProgress="0"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="@drawable/accountdataprogress"
android:layout_centerHorizontal="true" />
<TextView android:id="@+id/MiddleText" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="0%"
android:textColor="#000000" android:textStyle="bold"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout android:id="@+id/Middle"
android:layout_centerHorizontal="true" android:layout_width="250dip"
android:layout_height="wrap_content" android:layout_below="@+id/Top">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/PuttingBar"
android:layout_alignParentLeft="true">
</LinearLayout>
</RelativeLayout>
<View android:layout_width="fill_parent" android:layout_height="10dip"
android:background="#00000000" android:layout_below="@+id/Bottom" />
</RelativeLayout>
En Java, j'ai fait quelque chose comme ça.
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;
public class ProgressListAdapter extends BaseAdapter
{
private Context mContext;
private ArrayList<ProgressList> mPList;
private TextView mLeft, mMiddle, mRight, mTextOne;
private ProgressBar mCustomProgressBar;
private LinearLayout mLinearLayout;
public ProgressListAdapter(Context nContext, ArrayList<ProgressList> nPList)
{
this.mContext = nContext;
this.mPList = nPList;
}
@Override
public int getCount()
{
return mPList.size();
}
@Override
public Object getItem(int nPosition)
{
return mPList.get(nPosition);
}
@Override
public long getItemId(int nPosition)
{
return nPosition;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ProgressList mEntry = mPList.get(position);
if (convertView == null)
{
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.customprogress, null);
}
mLeft = (TextView) convertView.findViewById(R.id.LeftText);
mLeft.setText(mEntry.getValueText());
mMiddle = (TextView) convertView.findViewById(R.id.MiddleText);
mCustomProgressBar = (ProgressBar) convertView.findViewById(R.id.CustomPro);
int mBarPosition = Usage.mElapsed;
mLinearLayout = (LinearLayout) convertView.findViewById(R.id.PuttingBar);
View mView = new View(mContext);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(2, 25);
layoutParams.setMargins(mBarPosition, 0, 0, 0);
mView.setMinimumHeight(25);
mView.setMinimumWidth(2);
mView.setBackgroundColor(Color.rgb(12, 56, 99));
mLinearLayout.addView(mView, layoutParams);
mView.invalidate();
if(mEntry.getValueNumber() > mBarPosition)
{
mCustomProgressBar.setProgress(mBarPosition);
mCustomProgressBar.setSecondaryProgress(mEntry.getValueNumber());
}
else if(mEntry.getValueNumber() <= mBarPosition)
{
mCustomProgressBar.setProgress((mEntry.getValueNumber()));
mCustomProgressBar.setSecondaryProgress(0);
}
mMiddle.setText(Integer.toString(mEntry.getValueNumber()) + "%");
mTextOne = (TextView) convertView.findViewById(R.id.TextOne);
mTextOne.setText(mEntry.getValue());
mRight = (TextView) convertView.findViewById(R.id.RightText);
mRight.setText(mEntry.getValueOne());
return convertView;
}
}
Mais quand je le lance montre bar supplémentaire dans la barre de progression comme celui-ci
Tout le monde a fait genre de travail s'il vous plaît me donner la main. En attente d'une réponse fructueuse. Merci.
pouvez-vous montrer plus de code ?? car il semble que ceux-ci sont à l'intérieur d'une boucle essayez de définir l'orientation de la mise en page – PedroAGSantos
Dans votre code, vous affichez seulement un ajout de 'PuttingBar' mais vous avez évidemment une boucle ou plusieurs appels à votre extrait' addPuttingBar'. Notez également que vous avez codé en dur votre marge de gauche à 30, pas pourquoi vous l'avez fait. Pouvez-vous s'il vous plaît ajouter plus de code autour de l'extrait 'addPuttingBar'? – inazaruk
Bonjour, j'ai ajouté le code complet. Jetez un coup d'oeil s'il vous plait. Merci. –