Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Add OnClickBarListener
Browse files Browse the repository at this point in the history
  • Loading branch information
hadiidbouk committed Dec 5, 2017
1 parent f1c75c8 commit 2e3fccb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ChartProgressBar extends FrameLayout {
private int mBarTitleMarginTop;
private int mBarTitleSelectedColor;
private int mProgressDisableColor;
private OnBarClickedListener listener;

public ChartProgressBar(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
Expand Down Expand Up @@ -115,6 +116,10 @@ public void setDataList(ArrayList<BarData> dataList) {
}


public void setOnBarClickedListener(OnBarClickedListener listener){
this.listener = listener;
}

public void build() {

removeAllViews();
Expand Down Expand Up @@ -381,6 +386,8 @@ public void onClick(View view) {

oldFrameLayout = frameLayout;

listener.onBarClicked((int)frameLayout.getTag());

}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.hadiidbouk.charts;

public interface OnBarClickedListener {
void onBarClicked(int index);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.hadiidbouk.charts.BarData;
import com.hadiidbouk.charts.ChartProgressBar;
import com.hadiidbouk.charts.OnBarClickedListener;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements OnBarClickedListener {

private ChartProgressBar mChart;

Expand Down Expand Up @@ -42,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {

mChart.setDataList(dataList);
mChart.build();

mChart.setOnBarClickedListener(this);
mChart.disableBar(dataList.size() - 1);
}

Expand All @@ -60,4 +62,8 @@ public void BtnPressed(View view) {
break;
}
}

@Override public void onBarClicked(int index) {
Toast.makeText(this, String.valueOf(index), Toast.LENGTH_SHORT).show();
}
}

0 comments on commit 2e3fccb

Please sign in to comment.